git-diff-tree
Compare content differences between tree objects
TLDR
Compare two tree objects
Show changes between two specific commits
Display changes in patch format
Filter changes by a specific path
SYNOPSIS
git diff-tree [options] tree-ish-1 [tree-ish-2] [path...]
PARAMETERS
-r, --recursive
Recurse into subtrees when comparing files.
-m, --merges
Show diffs for all parents of a merge commit.
-c, --cc
Show combined diff for merge commits. Implies --merges.
--stdin
Read tree-ish arguments from standard input.
--stat[=
Generate a diffstat summary of file changes. Optional width for output column width.
--numstat
Similar to --stat, but shows number of added and deleted lines, and pathname.
--name-only
Show only names of changed files.
--name-status
Show names and status (A, C, D, M, R, T, U, X, B) of changed files.
--raw
Show the raw Git diff output format, which includes modes and object IDs.
-z
Use NUL character as file name separator, instead of newline. Useful for scripting.
--diff-filter=...
Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B).
--find-copies[=
Detect copied files, with optional similarity index n (0-100%).
--find-renames[=
Detect renamed files, with optional similarity index n (0-100%).
--find-rewrites[=
Detect rewritten files, with optional similarity index n (0-100%).
--no-renames
Turn off rename detection.
--submodule[=
Specify how changes in submodules are shown. Format can be 'short' or 'log'.
The object name of the first tree or commit to compare (e.g., a branch name, commit hash, or tag).
The object name of the second tree or commit to compare. If omitted, and tree-ish-1 is a commit, it compares tree-ish-1 to its first parent.
Limit the diff to the specified paths (directories or files) within the trees.
DESCRIPTION
git-diff-tree is a plumbing command used to compare the content and mode of blobs or trees between two tree-ish objects. It outputs the differences as a raw diff or a diffstat, showing what changed between the specified trees. Unlike the more user-friendly git diff (a porcelain command), git-diff-tree is designed for scripting and low-level operations, providing precise control over the comparison process. It can show changes introduced by a commit by comparing the commit's tree with its parent's tree. The output format is highly customizable, allowing users to extract specific information about added, deleted, or modified files, along with their modes and object IDs. This command is fundamental for understanding how Git tracks changes at a detailed object level and is often used by other Git commands internally.
CAVEATS
As a plumbing command, git-diff-tree's output is optimized for machine parsing rather than human readability, making it less intuitive for direct use compared to git diff. It operates purely on Git's object model and does not directly compare with the working directory or index.
RAW OUTPUT FORMAT
When using the --raw option, git-diff-tree outputs lines detailing the mode, object ID, and status (A, D, M, etc.) of files. This machine-readable format is essential for scripts that need to process file changes precisely and consistently.
COMPARING COMMITS
A very common use case for git-diff-tree is to see the exact changes introduced by a specific commit. This is typically achieved by comparing the commit's tree with its first parent's tree, for example, git diff-tree <commit>^ <commit>.
HISTORY
git-diff-tree has been a core component of Git since its inception, essential for understanding and calculating differences directly from Git's internal object model. Its stable, machine-readable output format has made it a foundational tool for building higher-level Git commands and custom scripts.
SEE ALSO
git diff(1), git rev-parse(1), git ls-tree(1), git show(1)