Reverting a Merge Commit

An entire real feature needs to be backed out — not just one line, the whole thing.

Sometimes the problem is not one bad line — it is an entire real feature the team decides not to ship after all. Grace Hopper's protein-shakes feature merged cleanly, two real commits, no conflicts. Now it needs to come out completely.\n\ngit revert works on merge commits too — but a merge has two real parents, and git genuinely cannot guess which side is "the one to keep." The -m 1 flag tells it explicitly: parent 1 is master, the side to revert back to. This one real flag is behind one of the most commonly searched git questions there is.

Finding the Real Merge to Back Out

git log --oneline --merges -3
git show --stat <merge-hash>

A real, complete feature — two commits, one clean merge, now to be backed out entirely.

Why -m 1 Is Required

A merge commit has two real parents: the branch being merged INTO (master, parent 1) and the branch being merged IN (the feature, parent 2). git revert cannot guess which side represents "normal" and which represents "the change to undo" — -m 1 tells it explicitly: treat parent 1 (master) as the mainline, and undo everything the OTHER side introduced.

git switch -c revert/protein-shakes
git revert -m 1 <merge-hash>

A real, single new commit that removes everything the entire feature added — the whole file, gone, in one real, clean commit.

Landing It Normally

git switch master
git merge --no-ff revert/protein-shakes -m "Merge pull request: revert protein shakes"
git push

git revert -m 1 <merge-commit>

Reverts an entire real merge commit at once, using parent 1 (specified by -m) as the real mainline to revert back to. Confirmed directly in this lab: the whole protein-shakes feature, both real commits, removed in one clean revert.

Merge commit parents

A real merge commit always has two parents: parent 1 is the branch that was checked out (master), parent 2 is the branch that was merged in. -m 1 makes this real ordering explicit to revert, since it cannot be inferred automatically.

🔍 Discover the Real Merge to Back Out

Find the merge commit and see exactly what the whole feature introduced.

cd ~/team-recipes && git log --oneline --merges -3
cd ~/team-recipes && git show --stat $(git log --format=%H -1)

student@lab:~$ cd ~/team-recipes && git log --oneline --merges -3 020e0a5 (HEAD -> master, origin/master, origin/HEAD) Merge pull request: protein shakes 188a076 Merge pull request: revert cookie baking temp 2ab3e7b Merge pull request: faster cookies student@lab:~$ cd ~/team-recipes && git show --stat $(git log --format=%H -1) commit 020e0a5561b3445e3dfdcbc1fb303bfcbd62d80b (HEAD -> master, origin/master, origin/HEAD) Merge: 188a076 84a0ca3 Author: Ada Lovelace <ada@example.com> Date: Thu Jan 1 18:30:00 2026 +0000 Merge pull request: protein shakes protein-shakes.md | 5 +++++ 1 file changed, 5 insertions(+)

🔙 Revert the Entire Real Merge

One command, the whole feature removed — with -m 1 telling git which side is the real mainline.

cd ~/team-recipes && git switch -c revert/protein-shakes
cd ~/team-recipes && git revert -m 1 --no-edit $(git log --format=%H -1 master)
cd ~/team-recipes && ls protein-shakes.md
cd ~/team-recipes && git push -u origin revert/protein-shakes

student@lab:~$ cd ~/team-recipes && git switch -c revert/protein-shakes Switched to a new branch 'revert/protein-shakes' student@lab:~$ cd ~/team-recipes && git revert -m 1 --no-edit $(git log --format=%H -1 master) [revert/protein-shakes 6c15ffe] Revert "Merge pull request: protein shakes" Date: Mon Aug 24 19:58:33 2026 +0000 1 file changed, 5 deletions(-) delete mode 100644 protein-shakes.md student@lab:~$ cd ~/team-recipes && ls protein-shakes.md ls: protein-shakes.md: No such file or directory student@lab:~$ cd ~/team-recipes && git push -u origin revert/protein-shakes Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 311 bytes | 51.00 KiB/s, done. Total 2 (delta 1), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git * [new branch] revert/protein-shakes -> revert/protein-shakes branch 'revert/protein-shakes' set up to track 'origin/revert/protein-shakes'.

🔗 Land the Reversal Normally

The whole backed-out feature goes through the same real, reviewed process.

cd ~/team-recipes && git switch master
cd ~/team-recipes && git merge --no-ff revert/protein-shakes -m 'Merge pull request: revert protein shakes'
cd ~/team-recipes && git push
cd ~/team-recipes && git branch -d revert/protein-shakes
cd ~/team-recipes && git push origin --delete revert/protein-shakes

student@lab:~$ cd ~/team-recipes && git switch master Switched to branch 'master' Your branch is up to date with 'origin/master'. student@lab:~$ cd ~/team-recipes && git merge --no-ff revert/protein-shakes -m 'Merge pull request: revert protein shakes' Merge made by the 'ort' strategy. protein-shakes.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 protein-shakes.md student@lab:~$ cd ~/team-recipes && git push Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 233 bytes | 58.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git 020e0a5..f672dad master -> master student@lab:~$ cd ~/team-recipes && git branch -d revert/protein-shakes Deleted branch revert/protein-shakes (was 6c15ffe). student@lab:~$ cd ~/team-recipes && git push origin --delete revert/protein-shakes To ../recipes-origin.git - [deleted] revert/protein-shakes

Lab 2.6.2 complete. An entire real feature, backed out with one clean revert:\n\n\n Real merge discovered : ✅ git show --stat\n Whole feature reverted : ✅ git revert -m 1\n Landed the normal, reviewed way : ✅ merge --no-ff\n

Enable JavaScript to run the live terminal and track your progress.