git diff
git
Usage
git diff [--staged] [<commit>] [-- <path>]Shows only the changes you have not staged yet, which is why it looks empty right after git add — use --staged then.
Common flags
| Flag | Meaning |
|---|---|
| --staged | compare the staged snapshot with HEAD (same as --cached) |
| --stat | summary of files and line counts instead of the patch |
| -w | ignore whitespace changes |
| --name-only | list changed paths only |
| <a>...<b> | changes on b since it forked from a |
| -- <path> | restrict to a path; the -- keeps it from being read as a branch |
Examples
git diffshows only what is NOT staged yet
git diff --stagedshows what git commit would record
git diff main...featurethe work feature added since it left main
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git diff do?
Shows only the changes you have not staged yet, which is why it looks empty right after git add — use --staged then.
Q. How do I type it?
git diff [--staged] [<commit>] [-- <path>] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-diff