28

Let's say I am merging and just before the push I decide that I do not want to merge. Is it possible to get rid of the commits I have merged (and not pushed yet) without deleting my local branch or going into command line?

1

2 Answers 2

23

Happened to me while getting both push and pull failures:

  • "Push to origin/master was rejected"
  • "You have not concluded your merge (MERGE_HEAD exists). Please, commit your changes before you can merge"

To resolve:

  1. Go to "Version Control" window --> "Log" tab.
  2. Right click the previous commit --> "Reset Current Branch to Here..."
  3. In Git reset select "Mixed" (it keeps local changes).
  4. If there are later commits that were already pushed --> Pull from remote and merge as required.
  5. Commit the new changes, and Push to remote.
33

In the latest versions of IntelliJ (and I suppose other JetBrains products) there is a new option in the "Git branches" menu (bottom right of the screen) conveniently named "Abort Merge"...

Update: with the so-called "New UI" of the more recent JetBrains products, the "git branches" menu has moved to the top left, but it is the same menu and the "Abort merge" option will still appear there when applicable.

Git branches menu

2
  • 1
    This also works for most things with conflicts like reverts that result in needing a merge.
    – royalaid
    Feb 25, 2020 at 5:43
  • This wasn't in the Git Branches for me, but in the Git menu.
    – Philipp
    Nov 11, 2021 at 13:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .