Revert a Git commit

CLI

Git

Commit

Revert

Luc B.

Git

Reset

Git beginners often misunderstand the meaning of revert in git vernacular. Reverting means adding a new commit that undoes changes from a past commit or set of commits. Thus, unlike resetting, the commit history does not change in a revert.

This is useful when changes in one specific commit introduced a bug, but all other commits are fine and need to remain in the history. git revert will compute the changes made in the problematic commit and introduce a commit that undoes those changes.

Code Example

To create a revert commit, pass a commit's SHA-1 hash to git revert.

git revert 557cab31

If Git can't automatically remove changes from the commit, it will prompt you to resolve conflicts.