git diff
Example
git add .
git diffgit add .
git diff --stagedPlain git diff compares against the staging area, so staged changes only show with --staged.
Common mistakes
- Running
git diffaftergit addand seeing nothing, because staged changes need--staged.
Interview questions
How do I compare two branches with git diff?
Run git diff main..feature. To see only what the feature branch added since it split off, use git diff main...feature.
How do I list only changed file names?
Run git diff --name-only. Add --staged or two refs to choose what to compare.
What is the difference between git diff --staged and --cached?
None. They are two names for the same option.