Conflicts & Merge

How to Revert a Merged Pull Request in Git

Safely revert an accidentally merged Pull Request or merge commit using git revert with parent specification.

Instant 1-Line Solution
Safe CommandAdvanced
git revert -m 1 <merge-commit-hash>
When to use this scenario:A PR was merged into production/main that caused severe regressions, and you need to immediately roll it back.

Step-by-Step Execution Guide

1Find the merge commit hash
git log --oneline -n 5

Look for the commit that says "Merge pull request #..." and copy its hash.

2Revert the merge commit specifying parent 1
git revert -m 1 <merge-hash>

-m 1 tells Git that parent 1 (the main branch you merged into) should be preserved as the mainline.

3Push the revert to production
git push origin main

Deploys the rollback commit cleanly without rewriting shared branch history.

Critical Pitfalls & Precautions

  • β€’If you later want to re-merge the reverted branch, you must first revert the revert commit, otherwise Git considers those changes already incorporated.
Frequently Asked Questions

Revert a Merge Commit - Frequently Asked Questions

Common questions about safe rollback, remote history implications, and troubleshooting.

A merge commit has two parents. Git needs to know which parent branch to keep as the baseline, which is specified by "-m 1".