Reputation: 56935
First, I have to apologise - there are quite a number of 'how to undo a merge' questions on SO, but I'm so new at git that I really don't understand how to adapt the solutions them to my situation (though I'm sure they can be).
I have two branches, versionA
and versionB
. I made some changes in versionA
and merged them into versionB
, which is fine because the changes made in versionA
are forwards compatible. Then, I think I must have accidentally merged versionB
back into versionA
, which is not fine because versionB
is not backwards-compatible to versionA
.
How can I undo this?
To make things clearer, this is what I've done:
versionA C--C--C--C'--M2
\ /
\ /
versionB C--M--C--C*
M: merged versionA into versionB. this is fine.
M2: accidentally merged versionB back into versionA
This is what I want:
versionA C--C--C--C'
\
\
versionB C--M--C--C*
If I were on Mercurial I'd do hg rollback
and all would be fine, or I'd hg update C'
and make future commits off there for the versionA
branch, although this would leave M2
as a dead dangling head (hence I'd prefer the rollback
method).
What is the git way to scrub that last commit M2
from the versionA
branch? (All changes have been pushed).
Upvotes: 2
Views: 905
Reputation: 14508
You need to find the commit of the merge.
To find the merge commit try:
git log versionA ^versionB --ancestry-path --merges
The needed commit is the very last commit.
git revert -m 1 commit_hash
But please read up on Linus' write up: http://www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.txt
Also see: Which commit hash to undo a pushed merge using git-revert?
Upvotes: 1