Undo a git merge (hasn't been pushed yet)

Max Williams picture Max Williams · May 10, 2011 · Viewed 60.5k times · Source

I just committed some changes into one of my feature branches ("feedback_tab") then, checked out "master" and merged them in there. I actually meant to merge them into my "development" branch.

Now, master is ahead of 'origin/master' (its remote) by 17 commits - I haven't pushed the merge up (and don't want to, obviously). How can I revert master back to the same state as before the accidental merge? I'm confused between git revert and git reset with this stuff.

I looked in my git log and there's no entry for merging feedback_tab into master. I'd have thought it would be the top entry?

Bit confused :/ any help welcome! max

Answer

Hemerson Varela picture Hemerson Varela · Nov 6, 2014

To undo a merge that was NOT pushed:

git reset --merge ORIG_HEAD

If during the merge you get a conflict, the best way to undo the merge is:

git merge --abort