git revert creates a new commit that undoes the changes from a previous commit, without deleting history. It’s the safer way to back out a bad change in a shared branch because it preserves the record of what happened.

Quick Scoop

  • It reverses the effect of an earlier commit.
  • It does not rewrite history.
  • It is usually preferred over git reset when the branch is shared with other people.

Example

If commit abc123 broke something, you can run:

bash

git revert abc123

Git will open a commit message for the new “revert” commit, and that new commit will apply the opposite of abc123.

Revert vs reset

Command| What it does
---|---
git revert| Adds a new commit that undoes an earlier commit, keeping history intact. 19
git reset| Moves branch history backward, which can rewrite history. 3

When to use it

Use git revert when you want to safely undo a commit on a branch that others may already have pulled. It’s also useful when you want a clear audit trail of the change and its reversal.

TL;DR: git revert means “make a new commit that cancels an old one,” not “erase the old commit.”