Skip to main content

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, and show
  • 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:

  1. What is the difference between working tree, index, and repository?
  2. What does git diff compare?
  3. What does git diff --staged compare?
  4. What does HEAD usually point to?
  5. What does git show HEAD tell you that git status does not?

If more than two answers are weak, revisit Cluster 1 before continuing.

Compare and Distinguish​

Pair 1​

Compare:

  • git status
  • git 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 --oneline
  • git show HEAD

Explain when you would prefer each one.

Common Mistake Check​

For each mistake:

  1. say what is wrong
  2. write the safer move
  3. explain why

Mistakes:

  1. Committing without checking what is staged.
  2. Using git pull before reading current local state.
  3. Assuming a clean git diff means nothing is staged.
  4. Thinking origin/main updates by itself without communication.

Mini Application​

Create this scenario:

  1. one modified tracked file
  2. one staged tracked file
  3. 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: