Gitflow
🔄Reverting a Merge CommitHard+650 XP
Workshop
Scenario reference

Reverting a Merge Commit: the situation, step by step

The situation

Feature merge introduced a production bug. `git revert` on merges is special — two parents, Git doesn't know which to keep.

Merge hash is m3rg3h4. Parent 1 = main. Parent 2 = feature.

Hard · 4 steps · +650 XP

What you will practice

This scenario walks through 4 steps, in order:

  1. 01View log to find merge commit
  2. 02Revert merge with -m 1 (keep main parent)
  3. 03Verify revert commit
  4. 04Push fix
Reveal the step-by-step commands

Try the terminal first — you learn more by doing. When you want to check yourself, here is the command for each step.

  1. 1. View log to find merge commit
    git log --oneline
  2. 2. Revert merge with -m 1 (keep main parent)
    git revert -m 1 m3rg3h4
  3. 3. Verify revert commit
    git log --oneline
  4. 4. Push fix
    git push origin main

Key takeaway

-m 1 keeps parent 1 (main). To re-merge later, first revert the revert.