Interview Prep/Git & GitHub/Undoing Mistakes

A bad commit is already on shared `main`. Others have pulled it. How do you undo it?

IntermediateScenarioUndoing Mistakes
Answer

Situation read → Rewriting shared history would break everyone's clones.

What I'd do →

  1. git revert <bad-sha> creates a new commit that inverts the change.
  2. Push normally: git push origin main.
  3. For several commits: git revert --no-commit A..B && git commit.
  4. Open a ticket to fix the root cause properly, then reintroduce the change.

Why → Revert adds history instead of removing it, so every clone stays compatible.

Interview tip → "Revert shared, reset private" is the one-line rule.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes