Undo a commit that is already pushed (revert)

careful intermediate #revert#undo#pushed#production

When to use this: A bad commit is on GitHub (maybe live on Vercel) and you want to undo it without rewriting history.

Be careful with this one. Check git status before you run it.

Before you start

Steps

  1. Revert the commit

    terminal
    git revert 8c4d7e0

    Creates a NEW commit that applies the opposite changes. History is not rewritten, so it is safe for pushed commits. An editor opens for the message: save and close.

  2. Revert the most recent commit shortcut

    terminal
    git revert HEAD

    Same thing for the latest commit, without looking up an ID.

  3. Push the revert

    terminal
    git push

    Vercel deploys the reverted state.

How to verify it worked

  • git log --oneline -n 3 shows a Revert "..." commit on top.
  • The deployed site is back to the earlier behaviour.

How to undo it

Reverted by mistake? Revert the revert (it is also just a commit):

terminal
git revert <revert-commit-id>

Common errors and fixes

error: commit <id> is a merge but no -m option was given Reverting a merge commit needs the parent number: git revert -m 1 <id> (1 = keep the main line).
Conflicts during revert Resolve like a merge conflict, git add, then git revert --continue. Or give up with git revert --abort.

Q&A

Why revert instead of reset for pushed commits?

Reset rewrites history and would need a force push, which can break anyone else's copy. Revert only adds a commit, so everyone just pulls it.

Practice these as flashcards →

Terms in this scenario

Related scenarios

My notes

Saved in this browser only.