Git: how to reverse-merge a commit?

Mot picture Mot · Nov 27, 2009 · Viewed 101.2k times · Source

With SVN it is easy to reverse-merge a commit, but how to do that with Git?

Answer

Marcus Ericsson picture Marcus Ericsson · Dec 29, 2009

To revert a merge commit, you need to use: git revert -m <parent number>. So for example, to revert the recent most merge commit using the parent with number 1 you would use:

git revert -m 1 HEAD

To revert a merge commit before the last commit, you would do:

git revert -m 1 HEAD^

Use git show <merge commit SHA1> to see the parents, the numbering is the order they appear e.g. Merge: e4c54b3 4725ad2

git merge documentation: http://schacon.github.com/git/git-merge.html

git merge discussion (confusing but very detailed): http://schacon.github.com/git/howto/revert-a-faulty-merge.txt