Git Reset State Matrix: Predict All Three States
Four versions of one file
Earlier lessons introduced reset on a clean branch. Here the target commit contains A, current HEAD contains B, the index contains C and the working file contains D. The four letters are literal contents in a disposable repository, not hashes. Reset can move a branch while separately updating the index and working files. Before any real recovery, stop writes, inspect status and independently preserve valuable uncommitted data. A rescue branch saves committed history only. Use scenario matrix in lab-fixtures/chapter22-guide.md.
git status --shortgit show HEAD:notes.txtgit show :notes.txtcat notes.txtgit diffgit diff --cachedPredict the result before executing
For this specific dirty-file scenario, each mode starts from the same independent fixture.
| Mode | HEAD | Index | Working file |
|---|---|---|---|
| Before | B | C | D |
| soft | A | C | D |
| mixed | A | A | D |
| hard | A | A | A |
| merge | B | C | D (refused) |
| keep | B | C | D (refused) |
Soft preserves both uncommitted layers; mixed replaces the index but leaves the working file; hard overwrites both tracked layers and can remove obstructing untracked paths. An unrelated untracked draft survived in this fixture, not a guarantee for all untracked files. Do not execute hard reset on valuable data.
git branch rescue-tipgit reset --soft HEAD^git show HEAD:notes.txtgit show :notes.txtcat notes.txtConditional modes are not backups
Reset --merge refuses when a path differs between target and index and also has unstaged changes. Reset --keep refuses when a path changed between HEAD and target has conflicting local changes; unmerged entries also prevent keep. They are not universal safeguards for staged content. In the nonoverlap scenario only light.txt has a local edit; the target changes notes.txt, so both modes succeed and preserve the unstaged light edit. ORIG_HEAD records the previous tip for successful commit-level reset, but later operations may replace it.
git reset --keep HEAD^git status --shortgit show ORIG_HEAD:notes.txtcat light.txtChoose and verify
If you need to preserve the staging state, prefer soft for a justified private-history move; if you need to restage from scratch, mixed leaves working files. If the task is merely unstaging, do not move the branch at all: use the next lesson. Verify the exact three states and rescue reference, not just status. Practice: predict what changes if index C and working D are different and the target is A. Which information would a mixed reset no longer preserve in the index?
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Reset State Matrix: Predict All Three States — knowledge check
Reason about reset states and safe recovery.
Given HEAD B, index C, working D, target A, what is the soft result?
What does mixed reset preserve?
What does hard reset risk?
Why do merge and keep refuse the overlapping fixture?
What can happen to ORIG_HEAD later?