Git
soft mixed hard
Learn the difference between soft, mixed and hard modes.
Three reset modes: soft, mixed, hard
git reset has three primary modes affecting Git's three trees (Commit history, Staging area, Working directory) differently. --soft only moves commit history back, keeping changes staged. --mixed (the default mode) moves history and clears the stage, but leaves files in the working tree untouched.
# Undo keeping staging intact:
git reset --soft HEAD~1
# Undo and clear stage (default):
git reset --mixed HEAD~1
These modes dictate where your changes end up after the undo.
The dangerous mode: --hard
The --hard mode rolls back commit history, clears the staging area, and resets all files in the working directory to match the target commit. All local changes from uncommitted work or the undone commit are permanently destroyed. Therefore, --hard should only be used when discarding changes entirely.
# Discard all changes and reset to HEAD~1:
git reset --hard HEAD~1
Be cautious before running this command to avoid irreversible data loss.
Exercise Keep changes staged with soft reset
Undo the latest commit with git reset --soft HEAD~1 and print that changes remain staged with git status -s.
Show example solution
git init -q -b main
git config user.name "Deniz"
git config user.email "deniz@example.com"
echo "v1" > app.py
git add app.py
git commit -qm "v1"
echo "v2" > app.py
git commit -am -q "v2"
git reset --soft HEAD~1
git status -s
Test yourself
-
Where are changes from the undone commit located after running git reset --soft HEAD~1?
- They are moved only into the git stash stack
- They become untracked files in the working tree
- They wait ready in the staging area
- They are permanently deleted and unrecoverable
Show answer
They wait ready in the staging area — The --soft mode moves HEAD back while keeping changes staged; allowing you to recommit them immediately with a new message.
-
Reset discarding all changes
git reset ____ HEAD~1
Show answer
git reset --hard HEAD~1
-
Reset modes
- --soft
- Keeps changes in staging area
- --mixed
- Clears stage, keeps working files
- --hard
- Permanently deletes all changes
- Varsayılan mod
- Is the --mixed option
Next lesson: HEAD reference