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
-
Revert the commit
terminalgit revert 8c4d7e0Creates 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.
-
Revert the most recent commit shortcut
terminalgit revert HEADSame thing for the latest commit, without looking up an ID.
-
Push the revert
terminalgit pushVercel deploys the reverted state.
How to verify it worked
git log --oneline -n 3shows aRevert "..."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.