As I know in most situations, we do git revert -m 1 <merge-hash>
.
Why don't they default to the first parent on reverting a merge commit?
Any reasons behind?
Also, in what cases will we have to use -m 2
?
Git revert normally operates on commits with only a single parent. By not providing a default parent, git ensures that you're aware you're reverting a commit with 2 parents and have thought about what this means. (I'm just guessing as to why they don't default to -m 1
.)
You need to use -m 2
if you want to revert the changes made to the other branch. For example, assume you merge branch feature
into branch master
. Then, if you wanted to revert that merge commit, you'd normally revert the feature
branch "out" of the master branch with -m 1
. (The end result of the revert is the previous commit on the master branch.) If, instead, you did -m 2
, you'd be "reverting master out of the feature branch". This rarely makes sense (because the end state would be the same as the current HEAD
of your feature
branch, but with some extra commits that apply some changes and then undo them). (The end result of the revert would be the previous commit on the feature branch.)