git-diff-index
Compare index contents with a tree
TLDR
Compare the working directory with a specific commit
Compare a specific file or directory in working directory with a commit
Compare the working directory with the index (staging area) to check for staged changes
Suppress output and return an exit status to check for differences
SYNOPSIS
git diff-index [options] <tree-ish> [--] [path...]
PARAMETERS
--cached, --staged
Compare the specified tree object with the Git index.
--raw
Generate output in a raw format, showing only the differences essential for scripting.
--name-only
Show only the names of changed files, one per line.
--name-status
Show the names of changed files along with their status (e.g., A for added, M for modified, D for deleted).
--diff-filter=[(A|C|D|M|R|T|U|X|B)...]
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).
-M[
Detect renames. An optional similarity threshold
-C[
Detect copies. An optional similarity threshold
--no-renames
Turn off rename detection, even if configured globally.
-z
Separate output entries with a NUL character instead of a newline, useful for scripting with file names containing unusual characters.
The name of a tree object, typically a commit ID, branch name, or tag name, to compare against.
--
A standard convention used to separate command options from positional arguments (like paths).
[
Optional paths to limit the comparison to specific files or directories.
DESCRIPTION
The git-diff-index command is a low-level (plumbing) command used to compare a tree-ish object (like a commit, branch, or tag) against the Git index or the files in the working directory.
When invoked with the --cached or --staged option, it compares the specified tree-ish with the content of the Git index. Without these options, it compares the tree-ish with the files in the working directory.
Its primary purpose is to provide raw, scriptable output about differences, often used by other Git commands (like git diff) to perform their higher-level comparisons. It can detect changes, additions, deletions, renames, and copies of files between the two points of comparison. Its output format is terse and designed for machine parsing rather than human readability.
CAVEATS
This command is a low-level plumbing command. Its output format is designed for machine parsing and is not easily human-readable. It may behave unexpectedly or produce complex output for unmerged paths in the index.
RAW OUTPUT FORMAT
When using the --raw option, git-diff-index produces output lines that typically start with a letter indicating the status (A, C, D, M, R, T, U, X, B), followed by old and new mode, old and new object names (hashes), and finally the old and new file names. This format is highly precise and intended for automated parsing by scripts.
HISTORY
As a plumbing command, git-diff-index has been a fundamental part of Git since its early days. It provides the core functionality for comparing tree-like objects with the index or working tree, forming the basis for many higher-level git diff commands. Its stability and predictable output make it crucial for scripting and internal Git operations.
SEE ALSO
git diff(1), git diff-files(1), git diff-tree(1)