git reset
Resets the current HEAD to a specified state. Can unstage files or undo commits.
Syntax
git reset [<mode>] [<commit>]
Options
- --soft: Resets HEAD to the specified commit but keeps changes staged
- --mixed: Resets HEAD and unstages changes but keeps them in the working directory (default)
- --hard: Resets HEAD, staging area, and working directory — all changes are lost
- HEAD -- <file>: Unstages a file without changing the working directory
Example
git reset HEAD~1 git reset --soft HEAD~1 git reset --hard HEAD~3 git reset HEAD -- file.ts
Tip
Use --soft to undo a commit while keeping all changes staged for recommitting.