git revert
intermediateUndo a commit by adding a NEW commit that does the opposite.
git revertWhat it does
git revert builds an inverse of an old commit — a commit that reverses every change it made — and appends it to your history. History stays linear and shared-safe. You never rewrite, you never remove, you simply add a correction.
An inverse commit is appended — nothing in history is rewritten
Watch it — press play
A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.
Step 1
Shared branch, broken commit
A bad commit already went to every teammate. Rewriting it with reset would break their clones — so we add instead.
git revert 74d3b9fThe target: a bad commit buried in history
Under the hood
It's a three-way merge — almost
To revert commit X, Git computes the diff between X's parent and X, then applies that diff in reverse on top of the current tree. The result is a brand-new commit whose parent is your current HEAD.
A — B — C — D(you) revert C: A — B — C — D — C⁻ (C⁻ undoes C's changes)
Conflicts possible even though it's reverse
If later commit D also touched the lines C changed, reversing C conflicts with D's version. Git stops and lets you reconcile — exactly like a merge conflict.
The commit is preserved in history
Unlike reset's amputation, revert leaves C in place. The reflog never matters, the history tells the story truthfully: 'someone added this, then someone reversed it.'
Aliases the pros type
Memorize the git revert concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:
git config --global alias.st # → git revertg rvgit revertReverse a commit safely.
g rv -ngit revert --no-commitApply multiple reversions before a single commit.
Command anatomy
--no-commitApply the reverse changes but don't commit — batch several reverts.
-m <parent>Revert a MERGE commit — the given parent becomes 'theirs'.
-nDo not auto-commit, so you can review the result.
When to reach for it
A bug went live on shared main — undo it without a force-push: git revert <hash>.
CI is red due to a merged feature: revert it, fix, re-revert the revert later.
Rolling back a merge that broke a release.
Pro tip
The mental rule: RESET rewinds (rewrites local history), REVERT reverses (adds a correcting commit), CHERRY-PICK reproduces (copies a commit elsewhere). On a shared branch, only revert or cherry-pick are polite.