You staged a .gitattributes edit, then changed it again. A check against the working tree may now describe a rule that will not be in the next commit. For a pre-commit review, compare the effective working-tree value with git check-attr --cached, which uses the indexed .gitattributes rather than the working-tree copy.
Run in an empty scratch directory
Use Git 2.43 or later and Bash. Save as attrs.sh and run bash attrs.sh. The script creates a fresh attr-demo subdirectory, stages one synthetic rule, and changes the working copy without committing. The queried file paths need not exist for this rule check.
#!/usr/bin/env bash
set -eu
unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_ATTR_SOURCE
export GIT_ATTR_NOSYSTEM=1 GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null
mkdir attr-demo
cd attr-demo
git init -q
attr() { git -c core.attributesFile=/dev/null check-attr "$@"; }
printf '%s\n' '*.txt editorial-review=manual' > .gitattributes
git add .gitattributes
printf '%s\n' '*.txt -editorial-review' > .gitattributes
work=$(attr editorial-review -- release.txt figure.svg)
index=$(attr --cached editorial-review -- release.txt figure.svg)
test "$work" = $'release.txt: editorial-review: unset\nfigure.svg: editorial-review: unspecified'
test "$index" = $'release.txt: editorial-review: manual\nfigure.svg: editorial-review: unspecified'
printf 'Working tree\n%s\nIndex\n%s\n' "$work" "$index"Expected output
Working tree
release.txt: editorial-review: unset
figure.svg: editorial-review: unspecified
Index
release.txt: editorial-review: manual
figure.svg: editorial-review: unspecifiededitorial-review=manual assigns a string, and -editorial-review explicitly unsets the attribute. figure.svg matches neither rule, so its attribute is unspecified. This example uses a custom attribute to make the difference visible without changing any built-in file treatment. Git reports the effective value, not the rule’s origin or evidence that an external consumer acted on it.
Diagnose a surprising value
First confirm whether you want the working tree or index. In a real repository, inspect git diff --cached -- .gitattributes and git diff -- .gitattributes. Then check for nested attribute files and higher-priority overrides, including .git/info/attributes. Outside the fixture, system and user attribute files can affect the answer too. If a working-tree attribute file is missing, Git can fall back to its index version, so removing the working copy is not the same as staging its removal.
Use the human-readable form for ad hoc checks. For a tool that reads arbitrary path names, use Git’s NUL-delimited mode and parse fields instead of splitting on colons. If the fixture directory already exists, start in a new empty directory so the checks cannot inherit earlier staged changes.
References and related reading: git check-attr manual, gitattributes precedence and states, and Java Samples Git tutorials.