Undo without losing work · Lesson 10 of 15
Reset: soft, mixed and hard
See exactly how each mode moves HEAD, staging and files.
reset moves the branch name and HEAD to another commit, then decides what to do with staging and files. soft preserves both, mixed (the default) resets staging, and hard resets staging and files.
--soft: HEAD only
--mixed: + staging
--hard: + working tree
git init -q -b main echo "one" > app.txt git add app.txt git commit -q -m "One" echo "two" >> app.txt git commit -q -am "Two" git reset --soft HEAD~1 git status -s
--soft HEAD~1 is useful for rebuilding the last commit: history moves back while its change remains staged. Mixed leaves it unstaged. Hard makes tracked files match the target, discarding later edits.
Quick question
Which mode moves HEAD only and leaves changes staged?
Exercise
Make two commits, soft-reset one step, and print short status.
Expected output: M app.txt
git init -q -b main echo "one" > app.txt git add app.txt git commit -q -m "One" echo "two" >> app.txt git commit -q -am "Two" git status -s
Learn more from
Played 0 of 2 games
Sign in to save your progress and earn XP.