git-check-attr
Check Git attributes for a file
TLDR
Check the values of all attributes on a file
Check the value of a specific attribute on a file
Check the values of all attributes on specific files
Check the value of a specific attribute on one or more files
SYNOPSIS
git check-attr [--all | --cached | --source | --stdin] <attribute>... <path>...
git check-attr [--litmus] <attribute> <path>
git check-attr --help
PARAMETERS
--all
Show all attributes that are defined for the given paths.
--cached
Check attributes for the version of the paths in the index (staging area) rather than the working tree.
--source
Show the source of the attribute definition (e.g., the .gitattributes file path) along with its value.
--stdin
Read paths and attribute names from standard input, one per line. Each line should be in the format: attribute path.
--litmus
Interpret the given attribute as a boolean and output true or false based on its effective value for the path.
--help
Display help information for the command.
<attribute>...
One or more attribute names to query (e.g., text, binary, crlf).
<path>...
One or more paths (files or directories) for which to check attributes.
DESCRIPTION
git-check-attr is a utility command used to inspect and verify the Git attributes assigned to files and directories within a repository. These attributes, defined in .gitattributes files (at various levels like project, user, or global), dictate how Git should handle certain file types or paths. Examples include text, binary, diff, merge, crlf, export-ignore, and custom attributes.
The command allows users to query the effective value of specific attributes for given paths, helping to diagnose issues related to line endings, diff behavior, or export filtering. It can report whether an attribute is set, unset, true, false, or unspecified. It also supports checking attributes for cached (indexed) paths, providing the source of an attribute definition, or performing litmus tests for boolean attributes. This tool is invaluable for understanding Git's behavior concerning file handling and ensuring attribute configurations are working as expected.
CAVEATS
The command evaluates attributes based on the .gitattributes files found in the repository, .git/info/attributes, and the global attributes file. If an attribute is not explicitly defined for a path or inherits no value, its value might be unspecified. The --cached option is crucial when debugging issues related to staged content, as attributes can sometimes differ between the working tree and the index.
ATTRIBUTE VALUES
The output for an attribute can be set (attribute is present, no specific value like text), unset (attribute is explicitly unset with -attribute), true (attribute has a boolean true value), false (attribute has a boolean false value), or unspecified (attribute is not defined for the path in any relevant .gitattributes file).
RESOLUTION ORDER
Git resolves attributes from multiple sources in a specific order: .git/info/attributes (repository-specific, not tracked), then .gitattributes files in the repository hierarchy (from root down to the file's directory), and finally the file specified by core.attributesfile (global/user-specific, typically in your home directory).
HISTORY
git-check-attr was introduced in Git 1.7.0.4. Its primary purpose was to provide a robust and scriptable way to query Git attributes, complementing the more passive nature of .gitattributes files and internal Git attribute processing. Over time, options like --source and --litmus were added to enhance its debugging capabilities and provide more detailed attribute insights.
SEE ALSO
gitattributes(5), git-config(1), git-ls-files(1)