0
0
Gitdevops~10 mins

git reset soft vs mixed vs hard - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Process Flow - git reset soft vs mixed vs hard
Start: Commit History
Choose Reset Type
soft
Move HEAD
Changes staged
This flow shows how git reset moves HEAD and affects the staging area and working directory differently depending on soft, mixed, or hard options.
Execution Sample
Git
git reset --soft HEAD~1
# Moves HEAD back by one commit, keeps index and working directory

git reset --mixed HEAD~1
# Moves HEAD back by one commit, resets index, keeps working directory

git reset --hard HEAD~1
# Moves HEAD back by one commit, resets index and working directory
These commands move the current branch HEAD back by one commit with different effects on staged and unstaged changes.
Process Table
StepCommandHEAD PositionIndex (Staging Area)Working DirectoryEffect
1Initial stateCommit C3 (latest)Matches C3Matches C3All commits, index, and working directory in sync
2git reset --soft HEAD~1Commit C2Matches C3Matches C3HEAD moved back, index and working directory unchanged, changes staged
3git reset --mixed HEAD~1Commit C2Matches C2Matches C3HEAD and index moved back, working directory unchanged, changes unstaged
4git reset --hard HEAD~1Commit C2Matches C2Matches C2HEAD, index, and working directory all reset to commit C2, changes discarded
5EndAt chosen commitIndex and working directory state depend on reset typeWorking directory state depends on reset typeReset complete
💡 Reset commands complete after moving HEAD and adjusting index and working directory according to reset type
Status Tracker
VariableStartAfter soft resetAfter mixed resetAfter hard reset
HEADC3C2C2C2
IndexMatches C3Matches C3Matches C2Matches C2
Working DirectoryMatches C3Matches C3Matches C3Matches C2
Key Moments - 3 Insights
Why does 'git reset --soft' keep changes staged even though HEAD moves back?
Because soft reset only moves HEAD pointer back but does not change the index or working directory, so staged changes remain as they were (see execution_table row 2).
What happens to unstaged changes after 'git reset --mixed'?
Unstaged changes remain in the working directory because mixed reset resets the index to the commit but leaves the working directory untouched (see execution_table row 3).
Why does 'git reset --hard' discard changes in the working directory?
Hard reset resets HEAD, index, and working directory to the specified commit, so any changes not committed are lost (see execution_table row 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table. After 'git reset --soft HEAD~1', what does the index contain?
AIs empty
BMatches the commit HEAD points to (C2)
CMatches the latest commit C3
DMatches the working directory
💡 Hint
Check execution_table row 2 under 'Index (Staging Area)'
At which step does the working directory get reset to match the commit?
AAfter soft reset
BAfter hard reset
CAfter mixed reset
DNever
💡 Hint
See execution_table row 4 under 'Working Directory'
If you want to keep your working directory changes but unstage them, which reset should you use?
Agit reset --mixed
Bgit reset --hard
Cgit reset --soft
Dgit reset --merge
💡 Hint
Look at how index and working directory change in execution_table rows 2 and 3
Concept Snapshot
git reset moves HEAD pointer and optionally resets index and working directory.
--soft: moves HEAD only, keeps index and working directory (changes staged).
--mixed (default): moves HEAD and resets index, keeps working directory (changes unstaged).
--hard: moves HEAD, resets index and working directory (changes lost).
Use carefully to manage commit history and staged changes.
Full Transcript
This visual execution shows how git reset commands affect the commit pointer (HEAD), the staging area (index), and the working directory. Starting from a state with three commits, we move HEAD back one commit with three reset types. Soft reset moves HEAD but leaves index and working directory unchanged, so changes remain staged. Mixed reset moves HEAD and resets the index to match the commit, but leaves working directory changes unstaged. Hard reset moves HEAD and resets both index and working directory to the commit, discarding any changes. The tables track these states step-by-step, helping beginners see exactly what changes and when. Key moments clarify common confusions about staging and discarding changes. Quizzes test understanding of index and working directory states after each reset type.