LinuxCommandLibrary

git-diff-tree

Compare content differences between tree objects

TLDR

Compare two tree objects

$ git diff-tree [tree-ish1] [tree-ish2]
copy

Show changes between two specific commits
$ git diff-tree -r [commit1] [commit2]
copy

Display changes in patch format
$ git diff-tree [[-p|--patch]] [tree-ish1] [tree-ish2]
copy

Filter changes by a specific path
$ git diff-tree [tree-ish1] [tree-ish2] -- [path/to/file_or_directory]
copy

SYNOPSIS

git diff-tree [--stdin] [-m] [-s] [-v] [--no-commit-id] [--pretty] [--stat] [--summary] [--patch-with-stat] [--patch-with-raw] [--name-only] [--name-status] [-r] [-c] [--cc] [--root] [--merge] [<common diff options>] <tree-ish> [<tree-ish>] [--] [<path>…]

PARAMETERS

--stdin
    Read commit/tree pairs from stdin (NUL or LF separated)

-m
    Diff commit against each parent separately

-s
    Show summary only, suppress diff

--no-commit-id
    Omit commit SHA-1 from output header

--pretty[=<format>]
    Pretty-print commit before diff (uses placeholders)

--stat
    Generate diffstat (file change statistics)

--summary
    Show summary of changes (files added/modified/deleted)

--patch-with-stat
    Patch followed by diffstat

--patch-with-raw
    Patch with raw diff header (alias -v)

--name-only
    Show only names of changed files

--name-status
    Show names with status (A/M/D etc.)

-r
    Recurse into subtrees

-c
    Combined diff for merge commits (show common parts)

--cc
    Condensed combined diff for merges

--root
    Treat root commit as diff against empty tree

--merge
    Affects handling for merge commits

-p
    Generate patch (default with caveats)

--no-standard-format
    Omit standard raw header line

-R
    Reverse diff output

--abbrev[=<n>]
    Abbreviate object names to n digits

DESCRIPTION

git diff-tree is a low-level plumbing command in Git for showing differences between two tree-ish objects, such as commits, tags, or direct tree SHA-1s. Tree objects represent repository snapshots. When given a single tree-ish (e.g., a commit), it defaults to diffing against the commit's parents, useful for examining changes in a specific commit.

Output includes a header with raw change stats (colon-separated fields like mode, object names, status), followed by diffs. Options control format: summaries (--summary), statistics (--stat), full patches (-p or --patch), or raw combined with patch (--patch-with-raw). It supports recursive diffs (-r), merge handling (-c for combined, --cc for condensed), root diffs (--root treating root as empty tree), and omitting commit IDs (--no-commit-id).

Ideal for scripts needing stable, parseable output without porcelain overhead. Pairs well with git log --pretty=format:%H for batch processing. Accepts most git diff options like -R (reverse), --abbrev, --find-renames. Not suited for interactive use due to terse, machine-readable focus.

CAVEATS

Plumbing command; output format stable but machine-oriented, not user-friendly. May change subtly. Use git show or git diff for porcelain. Single tree-ish implies parent diff; specify two for direct tree comparison.

TYPICAL OUTPUT HEADER

First line: :100644 100644 9daefb... newf4a... M file.txt
Fields: src_mode dst_mode src_sha1 dst_sha1 status npath

EXAMPLES

git diff-tree HEAD
Summary + diff of last commit vs parents.

git diff-tree -r -c --cc HEAD~1
Recursive combined diff of merge.

git diff-tree --stdin < commits.txt
Batch diff multiple pairs.

HISTORY

Introduced in Git 0.99 (April 2005) as core plumbing for tree diffs. Evolved with Git's diff machinery; stable since 1.0 (2005). Key for scripting commit analysis in early Git workflows.

SEE ALSO

Copied to clipboard