Working tree, index, commits, branches — all comparable.
Show changes between two trees. With no arguments: working tree vs index. With one ref: working tree vs that ref. With two refs: between refs. With --cached: index vs HEAD. The same primitive backs every other 'what changed?' answer.
Diff is a tree-to-tree operation. The 'tree' on either side may be HEAD's tree, the index, or your working tree. The output is a unified diff — a textual delta — but it's computed from object-database trees, not from text files. That's why git diff is fast on huge repos: it's comparing tree objects, not running diff(1) on every file.
git diff [<options>] [<commit>] [--] [<path>...]
git diff [<options>] --cached [<commit>] [--] [<path>...]
git diff [<options>] <commit> <commit> [--] [<path>...]
git diff [<options>] <blob> <blob>| Flag | What it does |
|---|---|
--cached, --staged | Diff index vs HEAD — what would git commit write? |
--stat | Show file-level summary instead of full hunks. |
--name-only | Only file names that changed. |
--name-status | File names plus an A/M/D letter. |
-w, --ignore-all-space | Ignore whitespace differences entirely. |
-U<n> | Lines of context around each hunk. Default 3. |
--word-diff | Show changes at the word level instead of line level. |
--color-moved | Highlight moved blocks in a different color. Surprisingly useful. |
--minimal | Spend more CPU to produce a smaller diff. For review. |
git diff.git diff --cached.git diff main...feature.git diff --name-only main..feature.$ git diff$ git diff --cached$ git diff main..feature$ git diff main...feature$ git diff --name-status HEAD~5diff, diff --cached, diff <ref>, diff <a>..<b>.... (three dots) when comparing branches: it diffs from the merge-base, which is what you usually mean.diff.algorithm = histogram in config — better hunk grouping than default.--color-moved=zebra for code-review diffs. Once you see it you can't go back.A..B and A...B are different. Two dots: between commits. Three dots: from their merge-base.git diff on a binary file says 'binary files differ' and stops. Use --text to force a textual diff (it'll be ugly).--no-color | wc or -w toggled.Hit each option, then Check answers. Score is recorded; Next is always open.