foundation
git diff
Compare working tree, staged changes, commits, branches, and ranges before review, commit, or release.
`git diff` compares trees: working tree vs index, index vs HEAD, commit vs commit, branch vs branch.
git diff # unstaged changes
git diff --staged # staged vs HEAD
git diff main...feature # changes on feature since fork point
git diff v2.3.0 v2.4.0 --stat
| Comparison | Shows | |------------|-------| | `git diff` | Unstaged edits | | `git diff --staged` | What the next commit will include | | `git diff A B` | Difference between two commits/branches |
On interviews: unstaged vs staged, three-dot range for PR-style diffs, reviewing lockfiles and generated output.
Common pitfalls: diff hides semantic impact of renames; formatting-only diffs obscure logic; not checking staged diff before commit.
The trade-off is pre-commit inspection thoroughness versus speed — at minimum always review `--staged` before commit.
Checklist:
- Check both unstaged and staged diffs.
- Compare against the intended merge base.
- Review lockfiles and generated artifacts deliberately.
- Use `--stat` first on large ranges.