Git reset is one of Git’s most powerful commands, but it’s also one of the easiest to misuse. With the right approach, you can repair mistakes, clean up commits, and keep your repository in perfect order. The key is understanding how each mode behaves and when each should be used.
What Git Reset Does
git reset moves the current branch’s HEAD to a specified commit. Depending on the mode, it can change the staging area, the working directory, or both. This command is about rewinding and restructuring history without losing the commits unless you choose to discard them.
The three most common modes are:
- Soft reset (
--soft): Moves HEAD to the target commit and keeps all changes staged. Best for rewriting commit boundaries without touching file changes. - Mixed reset (
--mixed): Moves HEAD and clears the staging area, but leaves working directory changes intact. This is the default mode. - Hard reset (
--hard): Moves HEAD and discards all changes in staging and working directories. Use only when you’re sure you don’t need the changes.
Usability in Practice
Good Git reset usability means reducing risk. This starts with clear intent before executing any reset. Always view the commit log with git log --oneline to confirm the target commit. Use git status before and after the reset to verify your repository state.