Undo a Git merge that hasn't been pushed yet

Undo a Git merge that hasn’t been pushed yet

reflog

The first step would be to use reflog to find the commit right before the merge:

1
$ git reflog

reset

Once you find the commit that you want to revert back to, use the reset command

1
$ git reset --hard <commit-hash>

close behind the merge

If the commit you want to get back to is only one behind HEAD, then you can instead use ORIG_HEAD as a shortcut in the reset command:

  1. With modern Git, you can:
1
git merge --abort
  1. Older syntax:
1
git reset --merge
  1. Old-school:
1
2
3
4
5
$ git reset --hard

or

$ git reset --hard ORIG_HEAD