inspection

git diff

Shows line-level differences between commits, the index, and the working tree. Without arguments, compares unstaged changes to the index.

git diff [<options>] [<commit>] [--] [<path>...]

Common flags

Flag Purpose
--staged / --cached Diff the index against HEAD (what would be committed)
--stat Summary of changed files and line counts
--name-only Just list changed file paths
-w / --ignore-all-space Ignore whitespace differences
--word-diff Highlight word-level rather than line-level changes

Examples

git diff

Unstaged changes in the working tree

git diff --staged

What will go into the next commit

git diff main..feature -- src/

Compare two branches for a subdirectory

Gotcha

In `git diff`, A..B compares the two commits directly (same as `git diff A B`), while A...B diffs from their merge-base to B — different semantics from `git log`, not just reversed.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge