Interview Prep/Git & GitHub/Undoing Mistakes

You need to revert a merge commit on `main`. `git revert` says "commit is a merge but no -m option was given".

IntermediateScenarioUndoing Mistakes
Answer

Situation read → A merge has two parents, so Git cannot know which side's changes to undo.

What I'd do →

  1. Pick the mainline parent, which is normally parent 1 (the branch merged into): git revert -m 1 <merge-sha>.
  2. Push the revert commit.
  3. Remember the re-merge caveat: to reapply the feature later, revert this revert first.

Why → -m 1 means "keep the first-parent line, undo what the second parent brought in".

Interview tip → Check parents with git show --no-patch --format=%P <sha>.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes