How to revert a merge in git (git revert -m 1) and why re-merging does nothing

A pull request was merged, something broke, and you want it gone. If the merge created a merge commit, a plain git revert will not work. This is a short guide to doing it correctly and to the trap that catches people afterwards.

Why a plain revert fails

A merge commit has two parents. Git cannot tell which side you want to keep, so git revert stops with an error that the commit is a merge but no -m option was given.

The fix: -m 1

Run git revert -m 1 followed by the merge commit hash. The -m option names the mainline parent. Parent 1 is the branch you merged into (usually main) and parent 2 is the branch that was merged in. With -m 1, git keeps the main side and undoes what the branch brought in.

On GitHub

A merged pull request has a Revert button. It opens a new pull request that undoes the merge, with the right parent chosen for you. Merge it like any other pull request, and your normal deploy runs again with the old code.

The re-merge trap

After you revert a merge, git remembers that the branch was merged. If you fix the branch and merge it again, git compares the history, sees that the branch's old commits are already part of main, and brings in only the new commits. The changes that the revert removed do not come back. The merge looks successful and the feature is still missing.

Check before and after

How Merge Scheduler handles it

If a deploy fails after a scheduled merge, Merge Scheduler opens a revert pull request, merges it, and watches the redeploy. It uses GitHub's own revert, so the right parent is chosen for you. If the revert would conflict, or the redeploy also fails, it stops and tells you which step failed, so a person decides.

Do this in Merge Scheduler: Set up automatic revert for a failed deploy

Related: Merge commit vs squash vs rebase: what each GitHub merge actually does · How to automatically revert a failed deploy (and when not to) · Why your auto-rollback job can't push the revert to main