Menu
Coddy logo textTech

Diff The Staged Changes

Part of the Version Control section of Coddy's Terminal journey — lesson 16 of 58.

Once you stage changes with git add, plain git diff stops showing them. To see what is queued up for the next commit, use:

git diff --staged

(The flag --cached is an alias and does the same thing.) This is what you should run right before committing, to double-check exactly what will be saved.

The two diffs answer two different questions:

  • git diff: "what have I changed but not yet staged?"
  • git diff --staged: "what will go into the next commit?"

If you have both unstaged edits and staged edits, the two commands show different sets of lines. Knowing which is which prevents you from committing the wrong version.

challenge icon

Challenge

Easy

The folder contains config.txt with the content port=80, already committed. Change it to port=8080, stage the change, then run git diff --staged.

Cheat sheet

git diff --staged shows changes that are staged (queued for the next commit). Use it to verify what will be saved before committing:

git diff --staged

The two diff commands answer different questions:

  • git diff — changes not yet staged
  • git diff --staged (alias: --cached) — changes staged for the next commit

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control