LinuxCommandLibrary

git-check-attr

Check Git attributes for a file

TLDR

Check the values of all attributes on a file

$ git check-attr [[-a|--all]] [path/to/file]
copy

Check the value of a specific attribute on a file
$ git check-attr [attribute] [path/to/file]
copy

Check the values of all attributes on specific files
$ git check-attr [[-a|--all]] [path/to/file1 path/to/file2 ...]
copy

Check the value of a specific attribute on one or more files
$ git check-attr [attribute] [path/to/file1 path/to/file2 ...]
copy

SYNOPSIS

git check-attr [options] [--] <pathspec>

PARAMETERS

-a, --all
    List all attributes (including unspecified, true, false, set) for each path.

--cached
    Use .gitattributes from index only; ignore working tree files.

-t, --table
    Print results in tabular format (path TAB attr TAB value).

-z, --null
    Separate records/values with NUL instead of newline (for scripts).

--stdin
    Read lines from stdin as 'path attr1 attr2...'; outputs only requested attrs.

--stdin-paths
    Read one path per line from stdin; equivalent to command-line paths.

--path=<path>
    Set path for --stdin lines lacking a path (attributes only).

DESCRIPTION

git check-attr is a plumbing command that inspects attributes defined in .gitattributes files for specified paths. Attributes control Git behaviors like textconv filters, diff drivers, merge strategies, line ending conversion (e.g., crlf), and binary handling.

It aggregates rules from the repository root .gitattributes, directory-specific files, and $GIT_DIR/info/attributes, applying the first matching pattern per attribute. Output shows attribute names and values: unset (no rule), set (macro or true), true/false, or literal strings.

Ideal for scripting, debugging merge issues, or verifying if files have binary, filter=lfs, or custom settings. Default output lists only defined attributes per path; --all includes unspecified ones. Supports stdin for batch processing, making it pipe-friendly (e.g., git ls-files | git check-attr --stdin-paths).

Considers working tree and index by default; --cached limits to index. Paths can be tree-ish:path or relative.

CAVEATS

Plumbing command: output format unstable, parse with --table -z for scripts.
Relative paths from current directory; tree-ish:path supported.
Honors core.attributesFile; no symlink following.

DEFAULT OUTPUT

<path>: <attr>: <value> (one line per attr per path).
Values: unspecified, set, unset, true/false, or string (quoted if spaces).

EXAMPLES

git check-attr binary -- README.md
README.md: binary: unspecified

git check-attr --all -t --cached --stdin-paths < paths.txt
Pipes paths, tab-separated all attrs from index.

HISTORY

Added in Git 1.7.2 (2010) as plumbing tool; --stdin in 1.8.4, --cached in 2.10, --stdin-paths in 2.24 for better scripting.

SEE ALSO

gitattributes(5), git-add(1), git-ls-files(1), git-diff(1)

Copied to clipboard