ProgramGuru

Inspect changes with status and diff

Inspect changes with status and diff

Before running a command that changes history, first inspect the state you already have. Git gives you separate comparisons for working-tree changes and staged changes.

What you’ll learn

  • Read git status.
  • Compare working and staged changes.
  • Use path-limited diffs.

Different diffs answer different questions

  1. git diff

    Working tree versus staging area.

    unstaged changes
  2. git diff --staged

    Staging area versus HEAD.

    next commit
  3. git diff A B

    Compare selected revisions.

    history comparison
history comparison

Ask Git a precise comparison question

git status summarizes state. git diff compares the working tree with the staging area. git diff --staged compares staged content with the current commit.

You can also compare commits, branches or paths directly, such as git diff main..feature or git diff HEAD~1 HEAD. The exact notation matters, so start with simple forms.

Inspect before and after staging

Run this in a disposable practice repository unless the lesson explicitly says otherwise.

printf "Second note\n" >> notes.txt
git diff -- notes.txt
git add notes.txt
git diff --staged -- notes.txt
git status --short

The first diff shows the working-tree edit. After staging, the ordinary git diff becomes empty for that path while --staged shows the change that is ready to commit.

Practice: Status and diff

Your task: Modify two files and stage only one. Use git status --short, git diff and git diff --staged to explain where each change lives.

Common pitfall to avoid

A clean git diff does not necessarily mean there are no changes. Your changes may already be staged, so check git diff --staged and git status too.

Check your understanding

Which command shows changes already staged for the next commit?
Choose one answer. You can try again.

Answer and explanation

git diff --staged

Correct.

Status and diff: what to remember

Inspect changes with status and diff is complete when you can explain the state being changed before you run the command, not merely repeat the syntax.

Read further: official supporting documentation.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Read history with log and show →