Skip to main content

Reading History, Diffs, and Repository State

What This Concept Is

Git fluency is mostly inspection fluency. Before you fix, merge, rebase, reset, or recover, you need to read the repository state correctly. The core inspection tools are:

  • git status
  • git diff
  • git diff --staged
  • git log
  • git show

Why It Matters Here

People often break Git history by acting too early. Inspection commands are what let you answer:

  • what changed?
  • what is staged?
  • what commit am I on?
  • what happened recently?
  • what branch shape am I working with?

If you can answer those cleanly, most "Git problems" become smaller.

Concrete Example

A compact inspection sequence looks like this:

git status
git diff
git diff --staged
git log --oneline --graph --decorate --all -5
git show HEAD

That gives you:

  • current file state
  • unstaged changes
  • staged changes
  • recent branch/merge shape
  • the exact content and metadata of the current commit

Common Confusion / Misconception

Misconception: git log is only for old history.

Correction: git log is a live inspection tool. A short graph view often tells you more than a GUI branch diagram.

Misconception: git status is enough by itself.

Correction: status tells you where changes are. diff and show tell you what the changes actually are.

How To Use It

Use inspection in layers:

  1. git status for the summary
  2. git diff or git diff --staged for exact line-level changes
  3. git log --oneline --graph --decorate --all for history shape
  4. git show <commit> for one commit in detail

Practical rule:

  • never merge, rebase, or reset before you can explain the current state in one sentence

Check Yourself

  1. Which command best answers "what is staged right now"?
  2. Which command best answers "what changed in this specific commit"?
  3. Why is --graph --decorate --all useful during branch work?

Mini Drill or Application

Build a three-commit repository and then:

  1. modify a file without staging it
  2. stage another file
  3. run status, diff, and diff --staged
  4. run git log --oneline --graph --decorate --all
  5. write one short explanation of what is modified, staged, and already committed

If your explanation is inaccurate, repeat the drill.

Read This Only If Stuck