How to unmerge a Git merge?

redAce picture redAce · Mar 8, 2015 · Viewed 126.4k times · Source

I accidentally did a git pull origin master from dev, and master got merged into dev. Is it possible to unmerge?

I've already seen different solutions, i tried this one from both dev and master : git revert -m 1 <commit> (once each) But i got : Everything is up-to-date, each time

I want to undo the merge master in dev : https://github.com/iliassk/PED_MyTodo/commits/dev commit:e382550

Answer

Andreas Wederbrand picture Andreas Wederbrand · Mar 8, 2015

You can reset your branch to the state it was in just before the merge if you find the commit it was on then.

One way is to use git reflog, it will list all the HEADs you've had. I find that git reflog --relative-date is very useful as it shows how long ago each change happened.

Once you find that commit just do a git reset --hard <commit id> and your branch will be as it was before.

If you have SourceTree, you can look up the <commit id> there if git reflog is too overwhelming.