It is used to undo changes by moving the HEAD (current branch pointer) to a different commit. It allows you to remove commits, unstage changes, or discard modifications in the working directory.
Types
| Reset Mode | Description |
|---|
--soft | Moves the branch pointer to a previous commit but keeps changes staged. |
--mixed | Moves the branch pointer to a previous commit and unstages changes but keeps them in the working directory. |
--hard | Moves the branch pointer to a previous commit and discards all changes. |
Commands
git reset <commit> – Moves the branch to a specific commit (default: mixed reset).
git reset --soft <commit> – Moves the branch to a commit, keeping changes staged.
git reset --mixed <commit> – Moves the branch to a commit, unstaging changes (default behavior).
git reset --hard <commit> – Moves the branch to a commit and deletes all changes.
git reset HEAD <file> – Unstages a file without changing its content.
git reset --hard HEAD – Discards all uncommitted changes.
git reset --keep <commit> – Like --hard but preserves uncommitted changes that do not conflict.
git reset --merge – Aborts a failed merge, similar to git merge --abort.
Comparison
| Feature | git reset | git revert |
|---|
| History | Removes commits | Creates a new commit to undo changes |
| Safety | Can be destructive (--hard) | Safe for shared branches |
| Use Case | Undo commits locally | Undo commits in a public branch |