Skip to main content
Back to command reference
Undoing Changes

git revert

Create a new commit that safely undoes a previous commit

Practical example

bash
git revert HEAD                  # undo the latest commit safely
git revert abc1234              # undo a specific commit
git revert HEAD~3..HEAD         # revert a range of commits

Command overview & how it works

Creates a brand new commit that inverses all the changes from a target commit, effectively undoing it without rewriting history. This is the safe undo command for commits that have already been pushed to shared branches. Unlike git reset, revert does not move branch pointers — it adds a new commit on top, so the existing history is preserved. Use git revert HEAD to undo the most recent commit, git revert HEAD~3 to revert the commit three steps back, or git revert <commit-hash> to target a specific commit. If the revert causes conflicts, resolve them normally and git revert --continue. Use git revert --no-commit to stage the inverse changes without automatically committing — useful for reverting multiple commits in a single commit. Revert is the default strategy for undoing changes in collaborative workflows.

Chapter 07 · Disaster Recovery Drills

Disaster-proof your Git workflow with the Field Guide

Learn how to rescue deleted branches, revive detached HEADs, and undo bad rebases without panic. 97-page PDF + ePub — ₹499.

Learn more

Practical tips

  • Prefer revert over reset for any commit that has been pushed to a shared branch — it adds a safe inverse commit.
  • Revert a range with git revert HEAD~3..HEAD, or stack multiple --no-commit reverts into a single commit.
  • If a revert conflicts, resolve the conflict, stage the files, and run git revert --continue.

Deep-dive guides & tutorials

In-depth walkthroughs and practical scenarios related to git revert

All guides →

Related commands

More from Undoing Changes