How to revert a merge commit (that you pushed)
Bits:
-
The merge-commit has two parents. The resultant revert-commit needs to know which parent is the mainline. This is why the
--mainline
option exists. - After reverting a merge-commit, we cannot just merge the branch again later and expect all the changes to come back.
Questions:
-
Why not just
checkout
the earlier commit and make a new one? This will work if and only if you are reverting a continuous range of commits that starts at HEAD and ends before the earlier commit. It will not work for reverting commits at arbitrary places in the history. -
Why not use
git reset
? This will rewrite public history which can create quite a pickle :)
References
https://git-scm.com/docs/git-revert
https://git-scm.com/book/en/v2/Git-Branching-Rebasing#The-Perils-of-Rebasing