Progress:
TIER 3 · MODULE 26· Expert

git diff-tree

What git show uses internally.

🎯 What & why

Diffs two tree-ish objects (or one tree against its parent) and is what git show and git log -p use under the hood. If you're scripting commit -> tree -> diff, this is the workhorse you actually call.

🧠 Mental model

Trees in, diff records out. With one tree it walks a commit's parents; with two it compares them directly; with -r it recurses into subdirectories instead of summarizing them as a single tree change.

🛠️ Synopsis

git diff-tree [--stdin] [-m] [-s] [-v] [--pretty] [-t] [-r] [--root]
              [<common-diff-options>] <tree-ish> [<tree-ish>] [<path>...]

🎚️ Switches & options

FlagWhat it does
<tree1> [<tree2>]One tree-ish diffs commit-vs-parent; two tree-ishes diffs them directly.
-r / --recursiveRecurse into subtrees; without it, directory changes collapse to a single entry.
--rootFor root commits, show the full tree as an addition instead of producing nothing.
-cFor merges, show a combined diff against all parents (only paths changed vs every parent).
--ccLike -c but further compresses uninteresting hunks; what git show uses for merges.
--combined-all-pathsWith -c/--cc, list the path under every parent (useful for renames across a merge).
-mFor merges, emit a separate diff against each parent instead of a combined one.
--name-only / --rawTrim output to paths only, or emit the machine-readable raw record format.

💡 Use cases

🧪 Examples

Patch for the tip commit, recursive
git diff-tree -p -r HEAD
Raw, NUL-terminated records for downstream tools
git diff-tree -r -z --raw HEAD^ HEAD
Combined merge diff like git show does
git diff-tree --cc -r <merge-sha>
Just the names of files changed in a commit
git diff-tree --no-commit-id --name-only -r HEAD

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.