soft mixed hard
- Git course
- Intermediate
- Lesson 42/82
- 4 min
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~1These 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~1Be cautious before running this command to avoid irreversible data loss.
Practice 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.
Starter code
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"
# HEAD~1'e soft reset at ve kisa durumu basSample 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 -sExpected output
M app.py
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 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 Correct answer
- They are permanently deleted and unrecoverable
Explanation: The --soft mode moves HEAD back while keeping changes staged; allowing you to recommit them immediately with a new message.
2 Reset discarding all changes
git reset ____ HEAD~1
git reset --hard HEAD~1
Explanation: The --hard option resets history, stage, and working directory to the target commit, discarding intermediate changes.
3 Reset modes
| Term | Meaning |
|---|---|
--soft |
Keeps changes in staging area |
--mixed |
Clears stage, keeps working files |
--hard |
Permanently deletes all changes |
Varsayılan mod |
Is the --mixed option |