Published on

How To Git Revert A Merged Pull Request

Authors

Once you merge a branch with lots of commits into another branch, reverting that branch out if it needs removed is not straight forward. I had to do this recently when it was neccasary, in order to fix a bug, to revert a pull request I had merged awhile back. This is how.

Reverting A Merge Commit

To do a git revert of a merge commit, you need to know which parent number to use. Use git log <merge-commit-hash> to view log for the merge commit. It will show two hashes for "merge", for example Merge: 41a7cd6 e4e47ca.

The first one should be the commit before the branch was branched off of the main branch. The second should be the last commit in the branch before the merge. Using a value of 1 for -m the mainline argument, reverts to the first hash, 2 coresponds to the second hash.

git log <merge-commit-hash> -m 1

Want to talk about this post? Discuss this on Twitter →

Found a typo or want to suggest an edit? Open a pull request →