I have a tracking branch to which I merged my master branch. There were conflicts that I fixed, committed and pushed. Now I need to revert that merge. How do I do it? I tried checking log, but obviously the history from master is now in the feature branch. Is there any hope?
2 Answers
From my understanding, it looks like you want to revert on your feature branch the merge commit that merged from your master branch.
You can do this in 2 ways, one which is more safe.
git revert -m <parent_index> HEAD
To get the parent index, run git show <merge commit SHA1>
and see the index (1-based) of the commit you want to revert to.
git reset --hard <feature branch SHA1>
This isn't the better option because it resets your history and you won't be able to get back to the merge commit even if you wanted to.
I suggest using the first one because you get to keep track of the merge commit, in case you want to see how you merged something later on.
-
1git show <merge commit SHA1> returns the same information set as git log. What I found confusing is the fact of two parent keys being present. In the end I have used git revert -m 1 <SHA of commit>. And I'm back to what I wanted. Commented Aug 15, 2013 at 15:32
git reset --hard <sha of last commit of feature branch>
We consider ur move is a merge commit. It will revert to feature branch and trash the merge commit.