Skip to content
Latchkey

git diff-tree: Usage, Options & Common CI Errors

git diff-tree compares the contents of two tree objects at the plumbing level.

When a hook or pipeline needs the exact list of files a commit changed, diff-tree is the stable, scriptable answer. It is the engine behind much of git log and is common in post-receive hooks.

What it does

git diff-tree compares two tree objects (or the trees of two commits) and prints the differences. With -r it recurses into subtrees, and its output format is stable enough to parse in scripts.

Common usage

Terminal
git diff-tree -r --name-only HEAD
git diff-tree --no-commit-id --name-only -r <sha>
git diff-tree -r <old-sha> <new-sha>
git diff-tree --root -r <first-commit>

Options

FlagWhat it does
-rRecurse into subtrees
--name-onlyPrint only changed file names
--name-statusNames plus add/modify/delete status
--no-commit-idOmit the leading commit SHA line
--rootShow the full diff for a root commit

Common errors in CI

A root (first) commit prints nothing because it has no parent; pass --root to diff it against the empty tree. Forgetting --no-commit-id leaves the commit SHA as the first output line, which then leaks into file lists when scripts read line by line.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →