tags:

views:

60

answers:

1

I am trying to revert a faulty merge, but the revert changes from both commands do not look right.

This is how I made the merge commit:

# merge master into branch:
git checkout branch
git merge master
# resolve conflicts
git commit
git push

Now I want to revert that merge with:

git log b2e
  commit b2e...
  Merge: de9... cf4...
git revert -m 1 -n b2e

The problem is that git status shows that it will only undo the conflicts I resolved, and not the entire merge. The command git revert -m 2 -n b2e will undo changes made to the branch before the merge, which I don't want either.

Second question is: How do I show what was changed in a merge commit?

git show b2e      # only shows the conflicts I resolved
git diff b2e de9  # does the same
git diff b2e cf4  # shows what is different between the branch and master

Update: The de9 commit was the right one to revert to and git diff b2e de9 does show what was committed. One reason I was confused was because a delete/keep conflict didn't show in the diff, so I thought there were changes git wasn't showing me. diff'ing to cf4, the commit from master, confused me even more because I didn't quite understand what was going on. There is no need to answer this question.

A: 

Git revert may not be what you want to do. The easiest way to get back to where you were before you merged is to run git reset --hard HEAD^ instead (or use the SHA1 of the commit you'd like to move back to, instead of HEAD^), especially if you're working on your own, or if you haven't yet pushed your merge and/or revert. If you revert a merge using revert, you may run into a situation in which you can't easily re-merge the commits you reverted, the revert itself is recorded as a new commit, and it can generally become confusing quickly. See here for examples and strategies: http://progit.org/2010/03/02/undoing-merges.html

urschrei