git revert
alone won\'t work. -m
must be specified, and I\'m pretty confused about it.
Anyone experienced this before?<
If you want to revert a merge
commit, here is what you have to do.
git log
to find your merge commit's id. You'll also find multiple parent ids associated with the merge (see image below).Note down the merge commit id shown in yellow.
The parent IDs are the ones written in the next line as Merge: parent1 parent2
. Now...
Short Story:
git revert -m 1
which will open a vi
console for entering commit message. Write, save, exit, done!Long story:
Switch to branch on which the merge was made. In my case, it is the test
branch and I'm trying to remove the feature/analytics-v3
branch from it.
git revert
is the command which reverts any commit. But there is a nasty trick when reverting a merge
commit. You need to enter the -m
flag otherwise it will fail. From here on, you need to decide whether you want to revert your branch and make it look like exactly it was on parent1
or parent2
via:
git revert
(reverts to parent2
)
git revert
(reverts to parent1
)
You can git log these parents to figure out which way you want to go and that's the root of all the confusion.