git revert
Creates a new commit that undoes a previous commit. Safe for shared branches — preserves history.
git reset
Moves the branch pointer back to an earlier commit. Has three modes: soft, mixed, and hard.
Revert
Use
git revert when you want to undo a commit while keeping the full Git history intact.git revert creates a new commit that reverses all the changes made in the specified commit. The original commit remains in the history.
For example, given this history:
test file, leaving your history as:
Reset
git reset moves the branch pointer back to an earlier commit. There are three modes:
soft
All changes from the undone commits are moved to the staging area. Nothing is lost — you can review and recommit them.git status to see the staged changes.
hard
All changes from the undone commits are permanently deleted.mixed
All changes from the undone commits are moved to the working directory (unstaged). This is the default mode if no flag is specified.git status to see the unstaged changes.
Comparison
When to use git revert
When to use git revert
Use
git revert when the commit has already been pushed to a shared remote branch. It adds a new commit to undo the change without rewriting history, which is safe for collaboration.When to use git reset --soft
When to use git reset --soft
Use
--soft when you want to undo a commit but keep all the changes staged and ready to be rewritten into a new commit.When to use git reset --mixed
When to use git reset --mixed
Use
--mixed (the default) when you want to undo a commit and review the changes before deciding what to stage and recommit.When to use git reset --hard
When to use git reset --hard
Use
--hard only when you are certain you want to permanently discard all changes from the undone commits. This is destructive and cannot be easily undone.