intermediate · 25 minute study
The commit records the index, not everything in your editor
Create focused commits without accidentally publishing unfinished edits or assuming that saved files are already part of a commit.
Useful preparation · 1 prerequisite
Use this as a map, not a lock. If these ideas are familiar, continue.
- Recovery & safe habits — An existing guided foundation in Learn → Try → Test → Build.
First, build a mental model
Keep three snapshots separate: the working tree is what you are editing, the index is what the next ordinary commit will record, and HEAD identifies the current committed history position.
- Editing a tracked file changes the working tree, not the existing commit.
- git add copies the selected current file content into the index. Later edits are not automatically restaged.
- git diff compares working tree to index; git diff --staged compares index to HEAD.
- An ordinary git commit records the index. Inspect that exact staged diff, including added files, before committing.
- Untracked and ignored files have separate status. Review scope and exclusions rather than assuming a broad git add is always appropriate.
# In a disposable learning repository:
# 1. HEAD contains src/score.js version A.
# 2. Edit it to version B.
git add src/score.js
# 3. Edit the same file again to version C.
git diff -- src/score.js
git diff --staged -- src/score.js
# An ordinary commit now records version B, not C.- HEAD
The committed file remains version A.
- Index
Staging captured version B when git add ran.
- Working tree
The later edit is version C. Its difference from B is still unstaged.
Production thinking
Take this beyond the example.
Keep unrelated work out of a change, inspect new files for private material and pair each validation claim with the tested snapshot. Staging is a review boundary, not merely a command to memorize.
Sources and further reading
Your evidence
unseen is a local learning signal, not a credential or proof of production competence.
Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.
Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.
Next lesson · Branches are names that move through a graph →