git-diff-index

Compare tree to working tree or index

TLDR

Compare index to commit
$ git diff-index HEAD
Compare working tree to commit
$ git diff-index [commit]
Check for differences
$ git diff-index --quiet HEAD
Raw output format
$ git diff-index --raw HEAD

SYNOPSIS

git diff-index [options] tree-ish [files...]

DESCRIPTION

git diff-index compares a tree object to the working tree or index, operating as a low-level plumbing command used internally by git diff for commit comparisons. It accepts a tree-ish (commit, branch, tag, or tree object) and compares it against either the index (with --cached) or the working tree.The tool is particularly useful in automation scenarios that need to detect whether files have changed since a specific commit, such as CI/CD pipelines checking for uncommitted modifications or scripts validating clean working directories. Its --quiet flag enables simple boolean checks for changes without processing full diff output.

PARAMETERS

--cached

Compare tree to index only, instead of the working tree.
-m
Treat files not checked out (present in the index but missing from the working tree) as modified rather than deleted.
--merge-base
Use the merge base of tree-ish and HEAD as the starting point for comparison.
--raw
Raw diff output (this is the default for this command).
--quiet
Exit with 1 if differences.
--name-only
Show file names only.
--name-status
Show file names and status.

INSTALL

sudo apt install git
sudo dnf install git
sudo pacman -S git
sudo apk add git
sudo zypper install git
brew install git
nix profile install nixpkgs#git

SEE ALSO

git-diff(1), git-diff-tree(1)