<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<article lang="en" id="gitattributes(5)">
<articleinfo>
    <title>gitattributes(5)</title>
        <indexterm>
                <primary>gitattributes(5)</primary>
        </indexterm>
</articleinfo>
<simplesect id="_name">
<title>NAME</title>
<simpara>gitattributes - defining attributes per path</simpara>
</simplesect>
<simplesect id="_synopsis">
<title>SYNOPSIS</title>
<simpara>$GIT_DIR/info/attributes, .gitattributes</simpara>
</simplesect>
<simplesect id="_description">
<title>DESCRIPTION</title>
<simpara>A <literal>gitattributes</literal> file is a simple text file that gives
<literal>attributes</literal> to pathnames.</simpara>
<simpara>Each line in <literal>gitattributes</literal> file is of form:</simpara>
<literallayout class="monospaced">glob    attr1 attr2 ...</literallayout>
<simpara>That is, a glob pattern followed by an attributes list,
separated by whitespaces.  When the glob pattern matches the
path in question, the attributes listed on the line are given to
the path.</simpara>
<simpara>Each attribute can be in one of these states for a given path:</simpara>
<variablelist>
<varlistentry>
<term>
Set
</term>
<listitem>
<simpara>
        The path has the attribute with special value "true";
        this is specified by listing only the name of the
        attribute in the attribute list.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unset
</term>
<listitem>
<simpara>
        The path has the attribute with special value "false";
        this is specified by listing the name of the attribute
        prefixed with a dash <literal>-</literal> in the attribute list.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Set to a value
</term>
<listitem>
<simpara>
        The path has the attribute with specified string value;
        this is specified by listing the name of the attribute
        followed by an equal sign <literal>=</literal> and its value in the
        attribute list.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unspecified
</term>
<listitem>
<simpara>
        No glob pattern matches the path, and nothing says if
        the path has or does not have the attribute, the
        attribute for the path is said to be Unspecified.
</simpara>
</listitem>
</varlistentry>
</variablelist>
<simpara>When more than one glob pattern matches the path, a later line
overrides an earlier line.  This overriding is done per
attribute.</simpara>
<simpara>When deciding what attributes are assigned to a path, git
consults <literal>$GIT_DIR/info/attributes</literal> file (which has the highest
precedence), <literal>.gitattributes</literal> file in the same directory as the
path in question, and its parent directories (the further the
directory that contains <literal>.gitattributes</literal> is from the path in
question, the lower its precedence).</simpara>
<simpara>If you wish to affect only a single repository (i.e., to assign
attributes to files that are particular to one user&#8217;s workflow), then
attributes should be placed in the <literal>$GIT_DIR/info/attributes</literal> file.
Attributes which should be version-controlled and distributed to other
repositories (i.e., attributes of interest to all users) should go into
<literal>.gitattributes</literal> files.</simpara>
<simpara>Sometimes you would need to override an setting of an attribute
for a path to <literal>unspecified</literal> state.  This can be done by listing
the name of the attribute prefixed with an exclamation point <literal>!</literal>.</simpara>
</simplesect>
<simplesect id="_effects">
<title>EFFECTS</title>
<simpara>Certain operations by git can be influenced by assigning
particular attributes to a path.  Currently, the following
operations are attributes-aware.</simpara>
<simplesect id="_checking_out_and_checking_in">
<title>Checking-out and checking-in</title>
<simpara>These attributes affect how the contents stored in the
repository are copied to the working tree files when commands
such as <emphasis>git-checkout</emphasis> and <emphasis>git-merge</emphasis> run.  They also affect how
git stores the contents you prepare in the working tree in the
repository upon <emphasis>git-add</emphasis> and <emphasis>git-commit</emphasis>.</simpara>
<simplesect id="_literal_crlf_literal">
<title><literal>crlf</literal></title>
<simpara>This attribute controls the line-ending convention.</simpara>
<variablelist>
<varlistentry>
<term>
Set
</term>
<listitem>
<simpara>
        Setting the <literal>crlf</literal> attribute on a path is meant to mark
        the path as a "text" file.  <emphasis>core.autocrlf</emphasis> conversion
        takes place without guessing the content type by
        inspection.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unset
</term>
<listitem>
<simpara>
        Unsetting the <literal>crlf</literal> attribute on a path tells git not to
        attempt any end-of-line conversion upon checkin or checkout.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unspecified
</term>
<listitem>
<simpara>
        Unspecified <literal>crlf</literal> attribute tells git to apply the
        <literal>core.autocrlf</literal> conversion when the file content looks
        like text.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Set to string value "input"
</term>
<listitem>
<simpara>
        This is similar to setting the attribute to <literal>true</literal>, but
        also forces git to act as if <literal>core.autocrlf</literal> is set to
        <literal>input</literal> for the path.
</simpara>
</listitem>
</varlistentry>
</variablelist>
<simpara>Any other value set to <literal>crlf</literal> attribute is ignored and git acts
as if the attribute is left unspecified.</simpara>
</simplesect>
<simplesect id="_the_literal_core_autocrlf_literal_conversion">
<title>The <literal>core.autocrlf</literal> conversion</title>
<simpara>If the configuration variable <literal>core.autocrlf</literal> is false, no
conversion is done.</simpara>
<simpara>When <literal>core.autocrlf</literal> is true, it means that the platform wants
CRLF line endings for files in the working tree, and you want to
convert them back to the normal LF line endings when checking
in to the repository.</simpara>
<simpara>When <literal>core.autocrlf</literal> is set to "input", line endings are
converted to LF upon checkin, but there is no conversion done
upon checkout.</simpara>
<simpara>If <literal>core.safecrlf</literal> is set to "true" or "warn", git verifies if
the conversion is reversible for the current setting of
<literal>core.autocrlf</literal>.  For "true", git rejects irreversible
conversions; for "warn", git only prints a warning but accepts
an irreversible conversion.  The safety triggers to prevent such
a conversion done to the files in the work tree, but there are a
few exceptions.  Even though&#8230;</simpara>
<itemizedlist>
<listitem>
<simpara>
<emphasis>git-add</emphasis> itself does not touch the files in the work tree, the
  next checkout would, so the safety triggers;
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>git-apply</emphasis> to update a text file with a patch does touch the files
  in the work tree, but the operation is about text files and CRLF
  conversion is about fixing the line ending inconsistencies, so the
  safety does not trigger;
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>git-diff</emphasis> itself does not touch the files in the work tree, it is
  often run to inspect the changes you intend to next <emphasis>git-add</emphasis>.  To
  catch potential problems early, safety triggers.
</simpara>
</listitem>
</itemizedlist>
</simplesect>
<simplesect id="_literal_ident_literal">
<title><literal>ident</literal></title>
<simpara>When the attribute <literal>ident</literal> is set for a path, git replaces
<literal>$Id$</literal> in the blob object with <literal>$Id:</literal>, followed by the
40-character hexadecimal blob object name, followed by a dollar
sign <literal>$</literal> upon checkout.  Any byte sequence that begins with
<literal>$Id:</literal> and ends with <literal>$</literal> in the worktree file is replaced
with <literal>$Id$</literal> upon check-in.</simpara>
</simplesect>
<simplesect id="_literal_filter_literal">
<title><literal>filter</literal></title>
<simpara>A <literal>filter</literal> attribute can be set to a string value that names a
filter driver specified in the configuration.</simpara>
<simpara>A filter driver consists of a <literal>clean</literal> command and a <literal>smudge</literal>
command, either of which can be left unspecified.  Upon
checkout, when the <literal>smudge</literal> command is specified, the command is
fed the blob object from its standard input, and its standard
output is used to update the worktree file.  Similarly, the
<literal>clean</literal> command is used to convert the contents of worktree file
upon checkin.</simpara>
<simpara>A missing filter driver definition in the config is not an error
but makes the filter a no-op passthru.</simpara>
<simpara>The content filtering is done to massage the content into a
shape that is more convenient for the platform, filesystem, and
the user to use.  The key phrase here is "more convenient" and not
"turning something unusable into usable".  In other words, the
intent is that if someone unsets the filter driver definition,
or does not have the appropriate filter program, the project
should still be usable.</simpara>
</simplesect>
<simplesect id="_interaction_between_checkin_checkout_attributes">
<title>Interaction between checkin/checkout attributes</title>
<simpara>In the check-in codepath, the worktree file is first converted
with <literal>filter</literal> driver (if specified and corresponding driver
defined), then the result is processed with <literal>ident</literal> (if
specified), and then finally with <literal>crlf</literal> (again, if specified
and applicable).</simpara>
<simpara>In the check-out codepath, the blob content is first converted
with <literal>crlf</literal>, and then <literal>ident</literal> and fed to <literal>filter</literal>.</simpara>
</simplesect>
</simplesect>
<simplesect id="_generating_diff_text">
<title>Generating diff text</title>
<simplesect id="_literal_diff_literal">
<title><literal>diff</literal></title>
<simpara>The attribute <literal>diff</literal> affects how <emphasis>git</emphasis> generates diffs for particular
files. It can tell git whether to generate a textual patch for the path
or to treat the path as a binary file.  It can also affect what line is
shown on the hunk header <literal>@@ -k,l +n,m @@</literal> line, tell git to use an
external command to generate the diff, or ask git to convert binary
files to a text format before generating the diff.</simpara>
<variablelist>
<varlistentry>
<term>
Set
</term>
<listitem>
<simpara>
        A path to which the <literal>diff</literal> attribute is set is treated
        as text, even when they contain byte values that
        normally never appear in text files, such as NUL.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unset
</term>
<listitem>
<simpara>
        A path to which the <literal>diff</literal> attribute is unset will
        generate <literal>Binary files differ</literal> (or a binary patch, if
        binary patches are enabled).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unspecified
</term>
<listitem>
<simpara>
        A path to which the <literal>diff</literal> attribute is unspecified
        first gets its contents inspected, and if it looks like
        text, it is treated as text.  Otherwise it would
        generate <literal>Binary files differ</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
String
</term>
<listitem>
<simpara>
        Diff is shown using the specified diff driver.  Each driver may
        specify one or more options, as described in the following
        section. The options for the diff driver "foo" are defined
        by the configuration variables in the "diff.foo" section of the
        git config file.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_defining_an_external_diff_driver">
<title>Defining an external diff driver</title>
<simpara>The definition of a diff driver is done in <literal>gitconfig</literal>, not
<literal>gitattributes</literal> file, so strictly speaking this manual page is a
wrong place to talk about it.  However&#8230;</simpara>
<simpara>To define an external diff driver <literal>jcdiff</literal>, add a section to your
<literal>$GIT_DIR/config</literal> file (or <literal>$HOME/.gitconfig</literal> file) like this:</simpara>
<literallayout>[diff "jcdiff"]
        command = j-c-diff</literallayout>
<simpara>When git needs to show you a diff for the path with <literal>diff</literal>
attribute set to <literal>jcdiff</literal>, it calls the command you specified
with the above configuration, i.e. <literal>j-c-diff</literal>, with 7
parameters, just like <literal>GIT_EXTERNAL_DIFF</literal> program is called.
See <xref linkend="git(1)"/> for details.</simpara>
</simplesect>
<simplesect id="_defining_a_custom_hunk_header">
<title>Defining a custom hunk-header</title>
<simpara>Each group of changes (called a "hunk") in the textual diff output
is prefixed with a line of the form:</simpara>
<literallayout class="monospaced">@@ -k,l +n,m @@ TEXT</literallayout>
<simpara>This is called a <emphasis>hunk header</emphasis>.  The "TEXT" portion is by default a line
that begins with an alphabet, an underscore or a dollar sign; this
matches what GNU <emphasis>diff -p</emphasis> output uses.  This default selection however
is not suited for some contents, and you can use a customized pattern
to make a selection.</simpara>
<simpara>First, in .gitattributes, you would assign the <literal>diff</literal> attribute
for paths.</simpara>
<literallayout>*.tex   diff=tex</literallayout>
<simpara>Then, you would define a "diff.tex.xfuncname" configuration to
specify a regular expression that matches a line that you would
want to appear as the hunk header "TEXT", like this:</simpara>
<literallayout>[diff "tex"]
        xfuncname = "^(\\\\(sub)*section\\{.*)$"</literallayout>
<simpara>Note.  A single level of backslashes are eaten by the
configuration file parser, so you would need to double the
backslashes; the pattern above picks a line that begins with a
backslash, and zero or more occurrences of <literal>sub</literal> followed by
<literal>section</literal> followed by open brace, to the end of line.</simpara>
<simpara>There are a few built-in patterns to make this easier, and <literal>tex</literal>
is one of them, so you do not have to write the above in your
configuration file (you still need to enable this with the
attribute mechanism, via <literal>.gitattributes</literal>).  The following built in
patterns are available:</simpara>
<itemizedlist>
<listitem>
<simpara>
<literal>bibtex</literal> suitable for files with BibTeX coded references.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>cpp</literal> suitable for source code in the C and C++ languages.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>html</literal> suitable for HTML/XHTML documents.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>java</literal> suitable for source code in the Java language.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>objc</literal> suitable for source code in the Objective-C language.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>pascal</literal> suitable for source code in the Pascal/Delphi language.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>php</literal> suitable for source code in the PHP language.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>python</literal> suitable for source code in the Python language.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>ruby</literal> suitable for source code in the Ruby language.
</simpara>
</listitem>
<listitem>
<simpara>
<literal>tex</literal> suitable for source code for LaTeX documents.
</simpara>
</listitem>
</itemizedlist>
</simplesect>
<simplesect id="_customizing_word_diff">
<title>Customizing word diff</title>
<simpara>You can customize the rules that <literal>git diff --color-words</literal> uses to
split words in a line, by specifying an appropriate regular expression
in the "diff.*.wordRegex" configuration variable.  For example, in TeX
a backslash followed by a sequence of letters forms a command, but
several such commands can be run together without intervening
whitespace.  To separate them, use a regular expression such as</simpara>
<literallayout>[diff "tex"]
        wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"</literallayout>
<simpara>A built-in pattern is provided for all languages listed in the
previous section.</simpara>
</simplesect>
<simplesect id="_performing_text_diffs_of_binary_files">
<title>Performing text diffs of binary files</title>
<simpara>Sometimes it is desirable to see the diff of a text-converted
version of some binary files. For example, a word processor
document can be converted to an ASCII text representation, and
the diff of the text shown. Even though this conversion loses
some information, the resulting diff is useful for human
viewing (but cannot be applied directly).</simpara>
<simpara>The <literal>textconv</literal> config option is used to define a program for
performing such a conversion. The program should take a single
argument, the name of a file to convert, and produce the
resulting text on stdout.</simpara>
<simpara>For example, to show the diff of the exif information of a
file instead of the binary information (assuming you have the
exif tool installed):</simpara>
<literallayout>[diff "jpg"]
        textconv = exif</literallayout>
<note><simpara>The text conversion is generally a one-way conversion;
in this example, we lose the actual image contents and focus
just on the text data. This means that diffs generated by
textconv are <emphasis>not</emphasis> suitable for applying. For this reason,
only <literal>git diff</literal> and the <literal>git log</literal> family of commands (i.e.,
log, whatchanged, show) will perform text conversion. <literal>git
format-patch</literal> will never generate this output. If you want to
send somebody a text-converted diff of a binary file (e.g.,
because it quickly conveys the changes you have made), you
should generate it separately and send it as a comment <emphasis>in
addition to</emphasis> the usual binary diff that you might send.</simpara></note>
</simplesect>
</simplesect>
<simplesect id="_performing_a_three_way_merge">
<title>Performing a three-way merge</title>
<simplesect id="_literal_merge_literal">
<title><literal>merge</literal></title>
<simpara>The attribute <literal>merge</literal> affects how three versions of a file is
merged when a file-level merge is necessary during <literal>git merge</literal>,
and other programs such as <literal>git revert</literal> and <literal>git cherry-pick</literal>.</simpara>
<variablelist>
<varlistentry>
<term>
Set
</term>
<listitem>
<simpara>
        Built-in 3-way merge driver is used to merge the
        contents in a way similar to <emphasis>merge</emphasis> command of <literal>RCS</literal>
        suite.  This is suitable for ordinary text files.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unset
</term>
<listitem>
<simpara>
        Take the version from the current branch as the
        tentative merge result, and declare that the merge has
        conflicts.  This is suitable for binary files that does
        not have a well-defined merge semantics.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unspecified
</term>
<listitem>
<simpara>
        By default, this uses the same built-in 3-way merge
        driver as is the case the <literal>merge</literal> attribute is set.
        However, <literal>merge.default</literal> configuration variable can name
        different merge driver to be used for paths to which the
        <literal>merge</literal> attribute is unspecified.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
String
</term>
<listitem>
<simpara>
        3-way merge is performed using the specified custom
        merge driver.  The built-in 3-way merge driver can be
        explicitly specified by asking for "text" driver; the
        built-in "take the current branch" driver can be
        requested with "binary".
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_built_in_merge_drivers">
<title>Built-in merge drivers</title>
<simpara>There are a few built-in low-level merge drivers defined that
can be asked for via the <literal>merge</literal> attribute.</simpara>
<variablelist>
<varlistentry>
<term>
text
</term>
<listitem>
<simpara>
        Usual 3-way file level merge for text files.  Conflicted
        regions are marked with conflict markers <literal>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</literal>,
        <literal>=======</literal> and <literal>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</literal>.  The version from your branch
        appears before the <literal>=======</literal> marker, and the version
        from the merged branch appears after the <literal>=======</literal>
        marker.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
binary
</term>
<listitem>
<simpara>
        Keep the version from your branch in the work tree, but
        leave the path in the conflicted state for the user to
        sort out.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
union
</term>
<listitem>
<simpara>
        Run 3-way file level merge for text files, but take
        lines from both versions, instead of leaving conflict
        markers.  This tends to leave the added lines in the
        resulting file in random order and the user should
        verify the result. Do not use this if you do not
        understand the implications.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_defining_a_custom_merge_driver">
<title>Defining a custom merge driver</title>
<simpara>The definition of a merge driver is done in the <literal>.git/config</literal>
file, not in the <literal>gitattributes</literal> file, so strictly speaking this
manual page is a wrong place to talk about it.  However&#8230;</simpara>
<simpara>To define a custom merge driver <literal>filfre</literal>, add a section to your
<literal>$GIT_DIR/config</literal> file (or <literal>$HOME/.gitconfig</literal> file) like this:</simpara>
<literallayout>[merge "filfre"]
        name = feel-free merge driver
        driver = filfre %O %A %B
        recursive = binary</literallayout>
<simpara>The <literal>merge.*.name</literal> variable gives the driver a human-readable
name.</simpara>
<simpara>The &#8216;merge.*.driver` variable&#8217;s value is used to construct a
command to run to merge ancestor&#8217;s version (<literal>%O</literal>), current
version (<literal>%A</literal>) and the other branches&#8217; version (<literal>%B</literal>).  These
three tokens are replaced with the names of temporary files that
hold the contents of these versions when the command line is
built.</simpara>
<simpara>The merge driver is expected to leave the result of the merge in
the file named with <literal>%A</literal> by overwriting it, and exit with zero
status if it managed to merge them cleanly, or non-zero if there
were conflicts.</simpara>
<simpara>The <literal>merge.*.recursive</literal> variable specifies what other merge
driver to use when the merge driver is called for an internal
merge between common ancestors, when there are more than one.
When left unspecified, the driver itself is used for both
internal merge and the final merge.</simpara>
</simplesect>
</simplesect>
<simplesect id="_checking_whitespace_errors">
<title>Checking whitespace errors</title>
<simplesect id="_literal_whitespace_literal">
<title><literal>whitespace</literal></title>
<simpara>The <literal>core.whitespace</literal> configuration variable allows you to define what
<emphasis>diff</emphasis> and <emphasis>apply</emphasis> should consider whitespace errors for all paths in
the project (See <xref linkend="git-config(1)"/>).  This attribute gives you finer
control per path.</simpara>
<variablelist>
<varlistentry>
<term>
Set
</term>
<listitem>
<simpara>
        Notice all types of potential whitespace errors known to git.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unset
</term>
<listitem>
<simpara>
        Do not notice anything as error.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unspecified
</term>
<listitem>
<simpara>
        Use the value of <literal>core.whitespace</literal> configuration variable to
        decide what to notice as error.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
String
</term>
<listitem>
<simpara>
        Specify a comma separate list of common whitespace problems to
        notice in the same format as <literal>core.whitespace</literal> configuration
        variable.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
</simplesect>
<simplesect id="_creating_an_archive">
<title>Creating an archive</title>
<simplesect id="_literal_export_ignore_literal">
<title><literal>export-ignore</literal></title>
<simpara>Files and directories with the attribute <literal>export-ignore</literal> won&#8217;t be added to
archive files.</simpara>
</simplesect>
<simplesect id="_literal_export_subst_literal">
<title><literal>export-subst</literal></title>
<simpara>If the attribute <literal>export-subst</literal> is set for a file then git will expand
several placeholders when adding this file to an archive.  The
expansion depends on the availability of a commit ID, i.e., if
<xref linkend="git-archive(1)"/> has been given a tree instead of a commit or a
tag then no replacement will be done.  The placeholders are the same
as those for the option <literal>--pretty=format:</literal> of <xref linkend="git-log(1)"/>,
except that they need to be wrapped like this: <literal>$Format:PLACEHOLDERS$</literal>
in the file.  E.g. the string <literal>$Format:%H$</literal> will be replaced by the
commit hash.</simpara>
</simplesect>
</simplesect>
<simplesect id="_viewing_files_in_gui_tools">
<title>Viewing files in GUI tools</title>
<simplesect id="_literal_encoding_literal">
<title><literal>encoding</literal></title>
<simpara>The value of this attribute specifies the character encoding that should
be used by GUI tools (e.g. <xref linkend="gitk(1)"/> and <xref linkend="git-gui(1)"/>) to
display the contents of the relevant file. Note that due to performance
considerations <xref linkend="gitk(1)"/> does not use this attribute unless you
manually enable per-file encodings in its options.</simpara>
<simpara>If this attribute is not set or has an invalid value, the value of the
<literal>gui.encoding</literal> configuration variable is used instead
(See <xref linkend="git-config(1)"/>).</simpara>
</simplesect>
</simplesect>
</simplesect>
<simplesect id="_using_attribute_macros">
<title>USING ATTRIBUTE MACROS</title>
<simpara>You do not want any end-of-line conversions applied to, nor textual diffs
produced for, any binary file you track.  You would need to specify e.g.</simpara>
<literallayout>*.jpg -crlf -diff</literallayout>
<simpara>but that may become cumbersome, when you have many attributes.  Using
attribute macros, you can specify groups of attributes set or unset at
the same time.  The system knows a built-in attribute macro, <literal>binary</literal>:</simpara>
<literallayout>*.jpg binary</literallayout>
<simpara>which is equivalent to the above.  Note that the attribute macros can only
be "Set" (see the above example that sets "binary" macro as if it were an
ordinary attribute --- setting it in turn unsets "crlf" and "diff").</simpara>
</simplesect>
<simplesect id="_defining_attribute_macros">
<title>DEFINING ATTRIBUTE MACROS</title>
<simpara>Custom attribute macros can be defined only in the <literal>.gitattributes</literal> file
at the toplevel (i.e. not in any subdirectory).  The built-in attribute
macro "binary" is equivalent to:</simpara>
<literallayout>[attr]binary -diff -crlf</literallayout>
</simplesect>
<simplesect id="_example">
<title>EXAMPLE</title>
<simpara>If you have these three <literal>gitattributes</literal> file:</simpara>
<literallayout>(in $GIT_DIR/info/attributes)

a*      foo !bar -baz

(in .gitattributes)
abc     foo bar baz

(in t/.gitattributes)
ab*     merge=filfre
abc     -foo -bar
*.c     frotz</literallayout>
<simpara>the attributes given to path <literal>t/abc</literal> are computed as follows:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
By examining <literal>t/.gitattributes</literal> (which is in the same
   directory as the path in question), git finds that the first
   line matches.  <literal>merge</literal> attribute is set.  It also finds that
   the second line matches, and attributes <literal>foo</literal> and <literal>bar</literal>
   are unset.
</simpara>
</listitem>
<listitem>
<simpara>
Then it examines <literal>.gitattributes</literal> (which is in the parent
   directory), and finds that the first line matches, but
   <literal>t/.gitattributes</literal> file already decided how <literal>merge</literal>, <literal>foo</literal>
   and <literal>bar</literal> attributes should be given to this path, so it
   leaves <literal>foo</literal> and <literal>bar</literal> unset.  Attribute <literal>baz</literal> is set.
</simpara>
</listitem>
<listitem>
<simpara>
Finally it examines <literal>$GIT_DIR/info/attributes</literal>.  This file
   is used to override the in-tree settings.  The first line is
   a match, and <literal>foo</literal> is set, <literal>bar</literal> is reverted to unspecified
   state, and <literal>baz</literal> is unset.
</simpara>
</listitem>
</orderedlist>
<simpara>As the result, the attributes assignment to <literal>t/abc</literal> becomes:</simpara>
<literallayout>foo     set to true
bar     unspecified
baz     set to false
merge   set to string value "filfre"
frotz   unspecified</literallayout>
</simplesect>
<simplesect id="_git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
</simplesect>
</article>
