AI Hints
Home›Git & GitHub Tutorial›Fixing Real Mistakes
Git & GitHub · Lesson 99 of 144

Undoing a Merge

Revert -m 1.

⏱ 2 min read▶ Video at 1:48:51🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

You merged a branch into main, and pushed it. Then you discover the branch broke the site. Since it's shared, reset is off the table. You need to revert the merge.

Undoing a Merge
From the video: Undoing a Merge
  • A bad merge, already pushed
  • Reset is off the table
  • Revert the merge

git revert -m 1

The log shows our merge commit on top. Reverting a merge needs one extra option, dash m one. A merge commit has two parents, and dash m one tells Git to keep the first parent, which is main, and undo what the branch brought in. Git makes a new commit, and the huge text is gone.

git
git log --oneline -n 3
312954a (HEAD -> main) Merge branch redesign
b4bf8c2 (redesign) Huge text redesign
f63a17a Link to about page
git revert -m 1 --no-edit HEAD
[main 0e45ab5] Revert "Merge branch redesign"
 Date: Mon Jan 5 09:38:49 2026 +0000
 1 file changed, 1 deletion(-)
git log --oneline -n 2
0e45ab5 (HEAD -> main) Revert "Merge branch redesign"
312954a Merge branch redesign
tail -1 style.css
body { font-family: sans-serif; }

Good to know

Dash m one is almost always what you want, because the first parent is the branch you merged into. And remember, the revert is just a normal commit. So if the branch is fixed later, and you want it back, you revert the revert.

-m 1keep main's side
New commithistory intact
Safefor shared branches
Changed your mind?revert the revert

Summary

To undo a pushed merge, use git revert dash m one, and the merge commit. Next, rescuing work made on a detached head.

Key takeaways
  • git revert -m 1 <merge>
  • Keeps main's side
  • Safe after pushing
Next up: Rescuing Detached Commits — save them on a branch