Skip to content

diff-tree Git Command Guide

The git diff-tree command is used to compare the content and mode of blobs found via two tree objects. If there is only one tree reference given, the commit is compared with its parents.

Terminal window
git diff-tree [--stdin] [-m] [-s] [-v] [--no-commit-id] [--pretty] [-t] [-r] [-c | --cc] [--combined-all-paths] [--root] [--merge-base] [<common-diff-options>] <tree-ish> [<tree-ish>] [<path>...]
OptionDescription
—stdinRead commit references from stdin
-mConsider merge commits
-sSuppress diff output
-vVerbose mode
—no-commit-idSuppress commit ID output
—prettyShow header information in pretty format
-tShow tree entry for root
-rRecurse into sub-trees
-c, —ccShow combined diffs for merges
—combined-all-pathsInclude all paths in combined diffs
—rootInclude root when comparing with initial commit
—merge-baseCompare with merge-base of given commits
-p, —patchGenerate patch output
—statShow diff statistics
—rawGenerate raw diff format (default)
—colorShow colored diff
ParameterDescription
First tree/commit to compare
[]Optional second tree/commit (default: parents)
[…]Optional paths to limit comparison
Terminal window
git diff-tree -p HEAD~1 HEAD

Shows the differences between two commits in patch format.

Terminal window
git diff-tree --stat HEAD~1 HEAD

Displays summary statistics of changes between commits.

Terminal window
git diff-tree --merge-base HEAD HEAD~3

Compares current HEAD with the merge-base of HEAD and HEAD~3.

Terminal window
echo "HEAD" | git diff-tree --stdin --pretty

Reads commit references from standard input.

Terminal window
git diff-tree -c -p HEAD

Displays combined diff format for a merge commit showing changes from all parents.

To compare two specific commits, use:

Terminal window
git diff-tree <commit1> <commit2>

To show diffs for merge commits, use the -c or —cc option:

Terminal window
git diff-tree -c HEAD

How do I process multiple commits in a script?

Section titled “How do I process multiple commits in a script?”

To process multiple commits, use —stdin with commit IDs:

Terminal window
echo -e "HEAD~1\nHEAD" | git diff-tree --stdin --pretty

What is the difference between -c and —cc?

Section titled “What is the difference between -c and —cc?”

-c shows combined diff with one column per parent, while —cc omits any commit that contains only changes from one side of the merge.

How can I limit the diff to specific paths?

Section titled “How can I limit the diff to specific paths?”

To limit to specific paths, add them at the end:

Terminal window
git diff-tree HEAD~1 HEAD -- path/to/file

How do I show only names and status of changed files?

Section titled “How do I show only names and status of changed files?”

To show only names and status, use with —name-status:

Terminal window
git diff-tree --name-status HEAD~1 HEAD
  1. Analyzing commit changes and code evolution
  2. Scripting automated diff processing in CI/CD pipelines
  3. Building repository analysis and audit tools
  4. Creating custom Git workflow integrations
  5. Detecting file changes and renames between commits