Welcome to Shaun Luttin's public notebook. It contains rough, practical notes. The guiding idea is that, despite what marketing tells us, there are no experts at anything. Sharing our half-baked ideas helps everyone. We're all just muddling thru. Find out more about our work at bigfont.ca.

How to revert a merge commit (that you pushed)

Tags: git

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