Git Revert -m: Undo a Merge Without Erasing History
Undo content, not ancestry
A merge M joins main parent P1 and topic parent P2. If a released feature must be withdrawn, a new revert commit can reverse the net change of M relative to a chosen parent. This is not a reset and does not remove M or either parent from history. The number in -m is a parent position starting at 1, not a branch name or a commit ID.
Identify the mainline
In scenario C, main adds release.txt, topic adds gallery.txt, and merge-source tags their merge commit. Parent 1 is the pre-merge main commit; parent 2 is the topic tip. Inspect parent ordering and the differences before deciding. In this specific graph, choosing parent 1 reverses the gallery addition while preserving release.txt; choosing parent 2 would instead reverse the release.txt addition. Never assume parent 1 is always the intended baseline.
git rev-list --parents -n 1 merge-sourcegit diff merge-source^1 merge-sourcegit diff merge-source^2 merge-sourceRevert the merge on main
Start at the clean merge tip on main, preserving a reference to the original merge. In this fixture use -m 1. The new commit has one parent, M. The resulting tree matches P1; in a real project with subsequent commits, the inverse may conflict or interact with later changes, so test the result instead of expecting a byte-identical parent tree.
git revert -m 1 --no-edit merge-sourcegit log --graph --oneline --allgit diff --name-status merge-source HEADgit merge-base --is-ancestor merge-source HEADWhy merging again is different
After the revert, Git still considers the original topic commits integrated by ancestry. Merging unchanged topic does not restore gallery.txt. A later topic commit adding light.txt can merge successfully while gallery remains absent. In this fixture, reverting the revert before further integration restores the gallery; in a real project coordinate and test that decision or introduce a corrected new patch. Practice: does revert remove the merge from the graph? No.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Revert -m: Undo a Merge Without Erasing History — knowledge check
Reason about selective integration and backport verification.
What does -m 1 mean?
What is the parent of a successful ordinary merge revert?
Which file disappears after -m 1 in scenario C?
What happens to the original merge ancestry?
Will merging the unchanged topic restore its reverted changes?