All commands

git revert

intermediate

Undo a commit by adding a NEW commit that does the opposite.

What 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.

9a2f1c0init project4b7c2a5add components74d3b9fdead: old logine1b5a09feature A8c4f2e9revert "dead: old login"mainHEAD

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.

1 / 2

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 74d3b9f
9a2f1c0init project4b7c2a5add componentsc86d9eestyle layout74d3b9fdead: old logine1b5a09feature AmainHEAD

The target: a bad commit buried in history

Under the hood

1

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)
2

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.

3

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.'

Command anatomy

git revert <commit>
--no-commit

Apply the reverse changes but don't commit — batch several reverts.

-m <parent>

Revert a MERGE commit — the given parent becomes 'theirs'.

-n

Do 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.

Practice

A real repo, pre-seeded with history, runs right here — stage, commit, branch, stash, diff, even hit and resolve a real merge conflict. Nothing to install, nothing leaves your machine.

Open practice playground

Go deeper with