LinuxCommandLibrary

git-check-attr

Check Git attributes for a file

TLDR

Check the values of all attributes on a file

$ git check-attr --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 --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 [-a | attribute...] [--] pathname...

PARAMETERS

-a
    Show all attributes configured for the given pathnames.

attribute
    Show only the attributes whose names are specified.

--
    Separates pathnames from options. This is useful to prevent pathnames that begin with '-' from being interpreted as options.

pathname
    The pathnames to check attributes for.

DESCRIPTION

git-check-attr displays Git attributes of specified files. It traverses directories and checks for attributes set in .gitattributes files along the path from the repository root to each file. It provides a convenient way to verify which attributes are active for a file, helping to diagnose configuration issues or understand how Git will treat the file.

The command is particularly useful for debugging problems related to line ending conversions, file filtering, or other Git features that rely on attributes. By examining the attributes applied to a file, developers can ensure that their .gitattributes files are configured correctly and that Git is behaving as expected.

It supports multiple files and can print the attributes along with the files to which they are assigned. It is often used to verify that file-specific overrides set with attributes are being correctly picked up.

CAVEATS

The command only checks for attributes defined in .gitattributes files. Attributes set in the Git configuration (e.g., in .git/config or ~/.gitconfig) are not displayed. Also, it is important to be inside a git repo to make use of the command.

OUTPUT FORMAT

The output format consists of lines showing the path, attribute name, and attribute value, separated by colons. The value can be 'unset', 'unspecified', or the actual value. If you request all attributes using '-a', all configured attributes are listed even if their values are `unspecified`.

ATTRIBUTE PRECEDENCE

When multiple .gitattributes files apply to a file (e.g., in different subdirectories), the attribute closest to the file takes precedence. The command reflects this precedence, showing the attribute value that is actually in effect.

HISTORY

The git-check-attr command has been part of Git since its early days. It was developed alongside the .gitattributes feature to provide a way to inspect and verify the attributes applied to files in a Git repository. Its primary purpose has always been to aid in debugging and understanding how Git handles file-specific configurations.

SEE ALSO

git-attributes(5), git-config(1)

Copied to clipboard