↩️ Undoing

How to revert a commit in Git

Create a new commit that undoes the changes from a previous commit.

Revert the last commit
git revert HEAD

Creates a new commit that exactly reverses the last commit.

Revert a specific commit
git revert abc1234

Reverts a specific commit by its hash. Find the hash with git log.

Revert without auto-committing
git revert --no-commit HEAD

Stages the reversal but does not create the commit. Lets you inspect or modify first.

When to use: When you want to review or combine the revert with other changes.

Revert a range of commits
git revert HEAD~3..HEAD

Reverts the last 3 commits, creating a new revert commit for each.

← Back to Git Reference