Skip to content

check-attr Git Command Guide

The git check-attr command is used to display gitattributes information, showing whether each attribute is unspecified, set, or unset as a gitattribute on specified pathnames. It helps understand how different files are handled by Git based on .gitattributes rules.

Terminal window
git check-attr [--source <tree-ish>] [-a | --all | <attr>...] [--] <pathname>...
Terminal window
git check-attr --stdin [-z] [--source <tree-ish>] [-a | --all | <attr>...]
OptionDescription
-a, —allList all attributes that are associated with the specified paths
—cachedConsider .gitattributes in the index only, ignoring the working tree
—stdinRead pathnames from the standard input, one per line, instead of from the command line
-zThe output format is modified to be machine-parsable
—source=Check attributes against the specified tree-ish
ParameterDescription
Attribute name(s) to check
File path(s) to check attributes for
Terminal window
git check-attr diff org/example/MyClass.java

Shows if the ‘diff’ attribute is set for the given Java file.

Terminal window
git check-attr crlf diff myAttr -- org/example/MyClass.java

Displays the setting for crlf, diff, and myAttr attributes on the specified path.

Terminal window
git check-attr --all -- org/example/MyClass.java

Shows all attributes associated with the path, excluding unspecified ones.

Terminal window
git check-attr myAttr -- file1.txt file2.md

Reports myAttr setting for each of the listed files.

Terminal window
echo "README.md" | git check-attr --stdin diff

Reads pathnames from standard input instead of command line arguments.

Terminal window
git check-attr --source HEAD~1 diff script.py

Checks attributes as they were in the previous commit.

How do I check if a file has a specific gitattribute set?

Section titled “How do I check if a file has a specific gitattribute set?”

To check if a file has a specific gitattribute set, use:

Terminal window
git check-attr <attribute> <path>

To list all attributes for a file, run:

Terminal window
git check-attr --all <path>

How do I check gitattributes for multiple files at once?

Section titled “How do I check gitattributes for multiple files at once?”

To check gitattributes for multiple files at once, execute:

Terminal window
git check-attr <attr>... -- <path1> <path2>...

To use stdin to check attributes, use:

Terminal window
echo "<path>" | git check-attr --stdin <attr>

How do I check attributes for a specific commit?

Section titled “How do I check attributes for a specific commit?”

To check attributes for a specific commit, run:

Terminal window
git check-attr --source <commit> <attr> <path>

To get machine-readable output, use:

Terminal window
git check-attr -z <attr> <path>

Applications of the git check-attr command

Section titled “Applications of the git check-attr command”
  1. Debugging .gitattributes configurations to ensure proper file handling
  2. Verifying that files have expected attributes for diff, merge, or filter behaviors
  3. Checking attribute settings across multiple files during repository maintenance
  4. Troubleshooting inconsistent file behavior due to attribute inheritance
  5. Automating checks in CI/CD pipelines for correct attribute configurations
  6. Analyzing historical attribute settings for forensic repository analysis
  7. Validating attribute rules before committing changes to .gitattributes