LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-diff-index

Compare tree to working tree or index

TLDR

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

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
copy
sudo dnf install git
copy
sudo pacman -S git
copy
sudo apk add git
copy
sudo zypper install git
copy
brew install git
copy
nix profile install nixpkgs#git
copy

SEE ALSO

Copied to clipboard
Kai