Skip to main content

Git Revert

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/git-revert

In short

Git revert is a Git command that undoes an earlier commit by creating a new commit with the opposite changes, leaving the existing project history intact.

What is git revert?

git revert is the safe way to undo a commit that has already been shared. Instead of deleting the commit, Git works out the exact opposite of its changes (lines it added are removed, and lines it removed come back) and records that as a brand-new commit. The original commit stays in the history, followed later by a commit whose message begins with 'Revert'.

You pass the hash of the commit to undo, as in git revert a1b2c3d, and Git opens an editor for the message, or uses the default one if you add --no-edit. Because nothing already published is rewritten, teammates simply pull the revert like any other commit, which makes it the standard way to back out a bad change on main or a release branch. Reverting a merge commit needs -m 1 to tell Git which parent is the main line to keep.

Reverting is like printing a correction in a newspaper rather than recalling every copy already delivered: the original article stays on record, and the correction explains what changed. If later commits also touched the lines being reverted, Git may report a conflict, which you resolve as usual and finish with git revert --continue.

The most common confusion is git revert versus git reset. Reset moves a branch back and makes later commits disappear from it, which rewrites history and breaks other people's copies if those commits were pushed, while revert only ever adds a new commit. Revert is also narrower than a deployment rollback: a rollback puts a previous release back into production, while a revert changes the code itself, and teams often do both.

Key takeaways

  • git revert <hash> creates a new commit that reverses the changes of an earlier one.
  • History is not rewritten, so it is safe to use on shared branches like main.
  • Reverting a merge commit requires -m 1 to choose which parent to keep.
  • Conflicts are resolved as usual and finished with git revert --continue.
  • Use git reset for unpushed local commits and git revert for published ones.

Example

Backing out a bad commit safelybash
# Find the commit that introduced the problem
git log --oneline
# 9f8e7d6 Add discount banner
# a1b2c3d Change checkout validation   <- this one broke checkout

# Create a new commit that undoes it, using the default message
git revert --no-edit a1b2c3d

# Undo a merge commit, keeping the first parent (usually main)
git revert -m 1 4d5e6f7

# Share the fix like any other commit
git push

Readers ask

What is the difference between git revert and git reset?

git revert undoes a commit by adding a new commit with the opposite changes, so history only grows. git reset moves a branch back to an earlier commit and drops the later ones, which rewrites history and should be limited to commits you haven't pushed.

Can I revert several commits at once?

Yes. Pass several hashes, or a range such as git revert A..B for every commit after A up to and including B, and Git creates one revert commit for each. Add --no-commit to stage all the reversals and record them as a single commit instead.

How do I undo a revert?

Revert the revert commit itself with git revert <revert-hash>, which brings the original changes back as another new commit. This is the usual way to re-apply a change once the underlying problem has been fixed.

Often compared

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings