Working tree, index, commit
Know exactly where a change is before committing or switching context.
git status
20 min read, 25 min lab
operator
Git has multiple places work can live: working tree, index, commits, branches, and remotes. `git status` is the first read because it tells you what is modified, staged, untracked, and related to upstream.
You need to make a focused fix while unrelated local work exists.
Worked command
$ git status --short$ git diff -- app.js$ git add -p app.js$ git commit -m 'Fix terminal prompt copy'
Do not stage everything because it is fast.
Inspect status, inspect diff, stage intentionally, then commit.
You have two unrelated edits in app.js and want to commit only the prompt-copy fix. What does staging with `git add -p` actually buy you?
Show the answer
Correct: A. It lets you choose individual hunks so unrelated changes stay out of the commit
`git add -p` walks you through hunks so you stage only the focused change, keeping the commit clean. It never commits and never discards the skipped hunks; they simply stay unstaged in the working tree for later.
Practice checklist
- Create a throwaway repo.
- Make two unrelated edits.
- Stage only one hunk with `git add -p`.
Deliverable evidence
- Status before and after staging.
- A commit with one focused change.
shows: The states work passes through (working tree, index, commit/branch, remote), the commands that move it between them, and reflog as the local-only save-point net that reset --hard can otherwise destroy.
does not prove: It does not prove your repository is recoverable: reflog only protects commits Git has actually recorded, so unstaged or untracked working-tree changes wiped by reset --hard are not in scope and stay gone.
Commit these to memory, then drill them until recall is automatic.
cue You want to stage only part of a modified file, hunk by hunk, instead of the whole file.
show recall target
git add -p