Appearance
git diff quick reference
Algorithms
| Command | Use |
|---|---|
git diff --diff-algorithm=histogram | Noisy refactors, boilerplate files |
git diff --diff-algorithm=patience | Code reordering, shifted functions |
git diff (default = myers) | Fast, general use |
Set globally: git config diff.algorithm histogram
CI Gates
bash
git diff --quiet HEAD~1 -- src/ && echo "skip build" || echo "build needed"
git diff --cached --check # pre-commit whitespace check
git diff --name-only HEAD~1 HEAD | grep -q 'infra/' && terraform planRename/Copy
bash
git diff --find-renames=80% # tighten threshold
git diff --find-copies-harder # full copy detection (slow)
git diff --no-renames --name-only # disable, fastProgrammatic Output
bash
git diff --numstat HEAD~1 HEAD # added deleted file
git diff --shortstat HEAD~1 HEAD # summary line
git diff --name-only HEAD~1 HEAD # file paths only
git diff --name-status --diff-filter=A # only new files
git diff --raw HEAD~1 HEAD # compact, status codesDiff Filter Codes
A(dded) C(opied) D(eleted) M(odified) R(enamed) T(ype changed) U(nmerged) X(unknown) -- lowercase = exclude.
Comparing
bash
git diff main...develop # changes on develop since branch
git diff v2.3.0:vendor/lib.js v2.4.0:vendor/lib.js # specific file across tags
git diff --cached # staged vs HEAD
git diff # unstaged vs HEAD (after add)Merge Diffs
bash
git show <merge-sha> # combined diff
git diff-tree --cc -p <merge-sha> # CI audit of merge changesPerformance
bash
git diff-tree --no-commit-id -r --name-only HEAD~1 HEAD # fastest tree diff
git diff --no-textconv # skip binary text conversion
git config diff.renameLimit 5000 # raise rename detection ceilingWord Diff
bash
git diff --word-diff HEAD~1 -- docs/*.md
git diff --word-diff-regex='[^[:space:],.-]+'Exit Codes
0 = no diff, 1 = diff found, >1 = error.
bash
git diff --quiet HEAD~1 HEAD && echo "clean" || echo "changes"