Repository State Diagnostics
What This Practice Page Is For
This page checks whether you can actually read Git state instead of reacting to command output mechanically.
You should be able to:
- distinguish working tree, index, and last commit
- choose between
status,diff,diff --staged,log, andshow - explain repository state in one sentence before acting
Before You Start
Do the first pass from memory in a throwaway repository.
Use this rule:
- first inspect
- then explain
- only then change state
Retrieval Round
Answer from memory:
- What is the difference between working tree, index, and repository?
- What does
git diffcompare? - What does
git diff --stagedcompare? - What does
HEADusually point to? - What does
git show HEADtell you thatgit statusdoes not?
If more than two answers are weak, revisit Cluster 1 before continuing.
Compare and Distinguish
Pair 1
Compare:
git statusgit diff
Explain what each command is for and why one is not a substitute for the other.
Pair 2
Compare:
- modified
- staged
- committed
Give one sentence for each state.
Pair 3
Compare:
git log --onelinegit show HEAD
Explain when you would prefer each one.
Common Mistake Check
For each mistake:
- say what is wrong
- write the safer move
- explain why
Mistakes:
- Committing without checking what is staged.
- Using
git pullbefore reading current local state. - Assuming a clean
git diffmeans nothing is staged. - Thinking
origin/mainupdates by itself without communication.
Mini Application
Create this scenario:
- one modified tracked file
- one staged tracked file
- one untracked file
Then run:
git status
git diff
git diff --staged
git log --oneline --decorate --graph --all -3
Write a four-line diagnosis of the repository.
Two unrelated edits in one file
In the clean guided-lab repository, create a deliberately spaced text fixture:
printf 'First: original\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\nLast: original\n' > notes.txt
git add notes.txt
git commit -m 'Add two-note fixture'
Use your editor to change only the first line to First: clarified and the last line to Last: clarified. Save it. The unchanged middle lines separate the two changes into different hunks under ordinary diff settings.
git diff
git -c diff.context=3 -c diff.interHunkContext=0 add -p notes.txt
Read the displayed hunk. Answer y only for the first-line change and n for the last-line change; never rely on a memorized response order when the displayed content differs. If your configuration presents the edits together, quit with q, inspect the fixture and split the hunk with s where offered. No commit is needed until the staged diff is correct.
git diff --staged
git diff
git commit -m 'Clarify the first note'
git show HEAD:notes.txt
git add notes.txt
git commit -m 'Clarify the last note'
git status --short
After the first commit, its snapshot must contain the clarified first line and original last line; the working file contains both clarifications. The second commit contains the remaining last-line change and finishes clean. Repeat with fresh text if you cannot predict these snapshots.
Evidence Check
You are done only when you can:
- identify what is modified, staged, and untracked
- choose the right inspection command for each question
- explain why a command is safe before you use it
If You Got Stuck
Revisit: