In Git, a commit usually references only 1 parent commit.
However, if you merge
and got conflicts, if you merge
with the option --no-ff
(no fast forward) or if Git can't fast-forward, Git create a merge commit
.
A merge commit is a commit dedicated to link two branches by referencing the 2 commits that are the tip of the branches (2 parents in this case).
When you want to revert this type of commit, you need to specify which branch should be the remaining one. As stated in Git doc :
Reverting a merge commit declares that you will never want the tree
changes brought in by the merge
You have to revert with the option -m
(--mainline
) with a parent number.
The number of the branch you merged in is 1 and the number of the merged branch is 2.
In your case, to go back to the state of your master
branch before the merge of your feature branch, you should revert with the command
git revert c49aaca4acf461cc41390c1d1d3477f09e25a368 -m 1
Tip: before launching the revert
, create a new branch from your master
(assuming you are currently on it)
git checkout -b you-name-it
and execute the revert
on this new branch : if it has the expected result, checkout
again your master
branch and perform the revert
, if it hasn't you still have your master
branch intact.