Undo a merge you already pushed
Careful: rewrites history
Short answer
Run git revert -m 1 --no-edit <merge-commit> and push. -m 1 tells Git to keep your branch's side and undo what the merge brought in.
If you later want the reverted branch merged for real, Git thinks it's already merged: you'll need to revert this revert first. Talk to your team before reverting shared merges.
The commands, one by one
- 1
git revert -m 1 --no-edit HEADA merge commit has two parents:
1is the branch you merged into (main),2is the branch you merged.-m 1undoes everything the merge added on top ofmain. - 2
git pushShares the undo with everyone.
For your own repository: If the merge isn't the latest commit, use its hash from git log --oneline.