tags:

views:

485

answers:

3

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

+4  A: 

If I understand you correctly, you're talking about doing a svn merge -rn:n-1 to back out of an earlier commit, in which case, you're probably looking for git-revert.

Rudedog
+9  A: 

To create a new commit that 'undoes' the changes of a past commit, use:

$ git revert <commit>

It's also possible to actually remove a commit from an arbitrary point in the past by rebasing and then resetting, but you really don't want to do that if you have already pushed your commits to another repository (or someone else has pulled from you).

Ben James
You would probably need to supply `-m <parent number>` option to `git revert` to specify which change to revert. If you want to undo a merge of non-published history, use `git reset --hard HEAD^1`.
Jakub Narębski
A: 

To revert a merge commit, you need to use: git revert -m . 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^

git merge documentation: http://www.kernel.org/pub/software/scm/git/docs/git-merge.html

git merge discussion (confusing but very detailed): http://www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.txt

Marcus Ericsson