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
-m
Detect renames and copies more aggressively during merge diffs
-p, --patch
Generate plain patches showing hunk headers and context
-u
Synonym for -p, generate unified diffs (deprecated)
--no-index
Compare two directories without Git repository (rare for diff-index)
--cached
Compare index/tree-ish to index itself (limited use)
--patch-with-stat
Combined --stat and -p output
--no-color
Suppress colored diff output
--color[=<when>]
Enable color (always, never, auto)
--word-diff[=<mode>]
Show word-level diffs (plain, color, porcelain)
--stat
Generate diffstat summary (lines changed per file)
--summary
One-line summary per file (added/removed/renamed)
-R
Swap input/output for reverse diff
--full-index
Show full object names, not abbreviated
--binary
Diff binary files as base64 (well or raw)
--abbrev[=<n>]
Use n-digit object name abbreviations
--ext-diff
Use external diff driver
--no-ext-diff
Disable external diff driver
--textconv
Use textconv filters
--no-textconv
Disable textconv filters
--ignore-submodules[=<when>]
Ignore submodule changes (none, untracked, dirty, all)
--src-prefix=<prefix>
Set source prefix for "a/" in paths
--dst-prefix=<prefix>
Set destination prefix for "b/" in paths
--no-prefix
Omit a/ and b/ path prefixes
-q, --quiet
No output, exit 1 on differences
--relative[=<path>]
Make paths relative to given directory
--submodule[=<format>]
Diff submodule commits (diff, short)
--relative-submodules
Use relative paths for submodules
DESCRIPTION
git diff-index is a low-level Git porcelain command that compares the content and file modes (permissions) of blobs in the index (staging area) or a specified <tree-ish> against the corresponding files in the working tree.
Without a <tree-ish>, it diffs the current index against the working directory, revealing unstaged changes or discrepancies between staged content and disk files. When provided a <tree-ish> (like HEAD), it compares that tree's blobs to the working tree, useful for viewing changes since a specific commit.
Output defaults to a list of differing paths with status (e.g., modified, deleted). Options enable summaries, patches, stats, or quiet mode. It ignores untracked files and focuses only on tracked paths matching the <pathspec>.
Ideal for scripts checking if the working tree matches the index before commits, or generating diffs in automation. Supports advanced formatting like word diffs, color, and submodule handling, inheriting options from the git diff family.
CAVEATS
Ignores untracked files; does not detect new files unless in index. Output format sensitive to diff.algorithm config. Not for interactive use—prefer git diff.
EXIT STATUS
0 if identical or no changes; 1 if differences found; >1 on errors.
git diff-index --quiet HEAD checks if working tree clean vs HEAD.
COMMON USES
git diff-index HEAD: Working tree vs last commit.
git diff-index: Index vs working tree.
Use --name-only (inherited) for paths only.
HISTORY
Introduced in Git v0.99 (2005) as core plumbing command by Linus Torvalds. Evolved with diff family options; stabilized in Git 1.5+ (2007). Remains essential for scripts despite high-level alternatives like git diff.
SEE ALSO
git-diff-files(1), git-diff-tree(1), git-diff(1), git-status(1)


