<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">

<sect2 lang="en" id="gitattributes(5)">
    <title>gitattributes(5)</title>
    <date>2024-07-02</date>
<revhistory><revision><date>2024-07-02</date></revision></revhistory>
<indexterm>
<primary>gitattributes(5)</primary>
</indexterm>
<simplesect id="gitattributes(5)__name">
<title>NAME</title>
<simpara>gitattributes - Defining attributes per path</simpara>
</simplesect>
<simplesect id="gitattributes(5)__synopsis">
<title>SYNOPSIS</title>
<simpara>$GIT_DIR/info/attributes, .gitattributes</simpara>
</simplesect>
<simplesect id="gitattributes(5)__description">
<title>DESCRIPTION</title>
<simpara>A <emphasis>gitattributes</emphasis> file is a simple text file that gives
<emphasis>attributes</emphasis> to pathnames.</simpara>
<simpara>Each line in <emphasis>gitattributes</emphasis> file is of form:</simpara>
<literallayout class="monospaced">pattern attr1 attr2 ...</literallayout>
<simpara>That is, a pattern followed by an attributes list,
separated by whitespaces. Leading and trailing whitespaces are
ignored. Lines that begin with <emphasis>#</emphasis> are ignored. Patterns
that begin with a double quote are quoted in C style.
When the 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 <emphasis>-</emphasis> 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 <emphasis>=</emphasis> and its value in the
        attribute list.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unspecified
</term>
<listitem>
<simpara>
        No 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 pattern matches the path, a later line
overrides an earlier line.  This overriding is done per
attribute.</simpara>
<simpara>The rules by which the pattern matches paths are the same as in
<emphasis>.gitignore</emphasis> files (see <xref linkend="gitignore(5)" />), with a few exceptions:</simpara>
<itemizedlist>
<listitem>
<simpara>
negative patterns are forbidden
</simpara>
</listitem>
<listitem>
<simpara>
patterns that match a directory do not recursively match paths
    inside that directory (so using the trailing-slash <emphasis>path/</emphasis> syntax is
    pointless in an attributes file; use <emphasis>path/**</emphasis> instead)
</simpara>
</listitem>
</itemizedlist>
<simpara>When deciding what attributes are assigned to a path, Git
consults <emphasis>$GIT_DIR/info/attributes</emphasis> file (which has the highest
precedence), <emphasis>.gitattributes</emphasis> file in the same directory as the
path in question, and its parent directories up to the toplevel of the
work tree (the further the directory that contains <emphasis>.gitattributes</emphasis>
is from the path in question, the lower its precedence). Finally
global and system-wide files are considered (they have the lowest
precedence).</simpara>
<simpara>When the <emphasis>.gitattributes</emphasis> file is missing from the work tree, the
path in the index is used as a fall-back.  During checkout process,
<emphasis>.gitattributes</emphasis> in the index is used and then the file in the
working tree is used as a fall-back.</simpara>
<simpara>If you wish to affect only a single repository (i.e., to assign
attributes to files that are particular to
one user's workflow for that repository), then
attributes should be placed in the <emphasis>$GIT_DIR/info/attributes</emphasis> file.
Attributes which should be version-controlled and distributed to other
repositories (i.e., attributes of interest to all users) should go into
<emphasis>.gitattributes</emphasis> files. Attributes that should affect all repositories
for a single user should be placed in a file specified by the
<emphasis>core.attributesFile</emphasis> configuration option (see <xref linkend="git-config(1)" />).
Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME
is either not set or empty, $HOME/.config/git/attributes is used instead.
Attributes for all users on a system should be placed in the
<emphasis>$(prefix)/etc/gitattributes</emphasis> file.</simpara>
<simpara>Sometimes you would need to override a setting of an attribute
for a path to <emphasis>Unspecified</emphasis> state.  This can be done by listing
the name of the attribute prefixed with an exclamation point <emphasis>!</emphasis>.</simpara>
</simplesect>
<simplesect id="gitattributes(5)__reserved_builtin__attributes">
<title>RESERVED BUILTIN_* ATTRIBUTES</title>
<simpara>builtin_* is a reserved namespace for builtin attribute values. Any
user defined attributes under this namespace will be ignored and
trigger a warning.</simpara>
<section id="gitattributes(5)__emphasis_builtin_objectmode_emphasis">
<title><emphasis>builtin_objectmode</emphasis></title>
<simpara>This attribute is for filtering files by their file bit modes (40000,
120000, 160000, 100755, 100644). e.g. <emphasis>:(attr:builtin_objectmode=160000)</emphasis>.
You may also check these values with <emphasis>git check-attr builtin_objectmode -- &lt;file&gt;</emphasis>.
If the object is not in the index <emphasis>git check-attr --cached</emphasis> will return unspecified.</simpara>
</section>
</simplesect>
<simplesect id="gitattributes(5)__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>
<section id="gitattributes(5)__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 switch</emphasis>, <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>
<section id="gitattributes(5)__emphasis_text_emphasis">
<title><emphasis>text</emphasis></title>
<simpara>This attribute marks the path as a text file, which enables end-of-line
conversion: When a matching file is added to the index, the file's line
endings are normalized to LF in the index.  Conversely, when the file is
copied from the index to the working directory, its line endings may be
converted from LF to CRLF depending on the <emphasis>eol</emphasis> attribute, the Git
config, and the platform (see explanation of <emphasis>eol</emphasis> below).</simpara>
<variablelist>
<varlistentry>
<term>
Set
</term>
<listitem>
<simpara>
        Setting the <emphasis>text</emphasis> attribute on a path enables end-of-line
        conversion on checkin and checkout as described above.  Line endings
        are normalized to LF in the index every time the file is checked in,
        even if the file was previously added to Git with CRLF line endings.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unset
</term>
<listitem>
<simpara>
        Unsetting the <emphasis>text</emphasis> attribute on a path tells Git not to
        attempt any end-of-line conversion upon checkin or checkout.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Set to string value "auto"
</term>
<listitem>
<simpara>
        When <emphasis>text</emphasis> is set to "auto", Git decides by itself whether the file
        is text or binary.  If it is text and the file was not already in
        Git with CRLF endings, line endings are converted on checkin and
        checkout as described above.  Otherwise, no conversion is done on
        checkin or checkout.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unspecified
</term>
<listitem>
<simpara>
        If the <emphasis>text</emphasis> attribute is unspecified, Git uses the
        <emphasis>core.autocrlf</emphasis> configuration variable to determine if the
        file should be converted.
</simpara>
</listitem>
</varlistentry>
</variablelist>
<simpara>Any other value causes Git to act as if <emphasis>text</emphasis> has been left
unspecified.</simpara>
</section>
<section id="gitattributes(5)__emphasis_eol_emphasis">
<title><emphasis>eol</emphasis></title>
<simpara>This attribute marks a path to use a specific line-ending style in the
working tree when it is checked out.  It has effect only if <emphasis>text</emphasis> or
<emphasis>text=auto</emphasis> is set (see above), but specifying <emphasis>eol</emphasis> automatically sets
<emphasis>text</emphasis> if <emphasis>text</emphasis> was left unspecified.</simpara>
<variablelist>
<varlistentry>
<term>
Set to string value "crlf"
</term>
<listitem>
<simpara>
        This setting converts the file's line endings in the working
        directory to CRLF when the file is checked out.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Set to string value "lf"
</term>
<listitem>
<simpara>
        This setting uses the same line endings in the working directory as
        in the index when the file is checked out.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unspecified
</term>
<listitem>
<simpara>
        If the <emphasis>eol</emphasis> attribute is unspecified for a file, its line endings
        in the working directory are determined by the <emphasis>core.autocrlf</emphasis> or
        <emphasis>core.eol</emphasis> configuration variable (see the definitions of those
        options in <xref linkend="git-config(1)" />).  If <emphasis>text</emphasis> is set but neither of
        those variables is, the default is <emphasis>eol=crlf</emphasis> on Windows and
        <emphasis>eol=lf</emphasis> on all other platforms.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</section>
<section id="gitattributes(5)__backwards_compatibility_with_emphasis_crlf_emphasis_attribute">
<title>Backwards compatibility with <emphasis>crlf</emphasis> attribute</title>
<simpara>For backwards compatibility, the <emphasis>crlf</emphasis> attribute is interpreted as
follows:</simpara>
<screen>crlf            text
-crlf           -text
crlf=input      eol=lf</screen>
</section>
<section id="gitattributes(5)__end_of_line_conversion">
<title>End-of-line conversion</title>
<simpara>While Git normally leaves file contents alone, it can be configured to
normalize line endings to LF in the repository and, optionally, to
convert them to CRLF when files are checked out.</simpara>
<simpara>If you simply want to have CRLF line endings in your working directory
regardless of the repository you are working with, you can set the
config variable "core.autocrlf" without using any attributes.</simpara>
<screen>[core]
        autocrlf = true</screen>
<simpara>This does not force normalization of text files, but does ensure
that text files that you introduce to the repository have their line
endings normalized to LF when they are added, and that files that are
already normalized in the repository stay normalized.</simpara>
<simpara>If you want to ensure that text files that any contributor introduces to
the repository have their line endings normalized, you can set the
<emphasis>text</emphasis> attribute to "auto" for <emphasis>all</emphasis> files.</simpara>
<screen>*       text=auto</screen>
<simpara>The attributes allow a fine-grained control, how the line endings
are converted.
Here is an example that will make Git normalize .txt, .vcproj and .sh
files, ensure that .vcproj files have CRLF and .sh files have LF in
the working directory, and prevent .jpg files from being normalized
regardless of their content.</simpara>
<screen>*               text=auto
*.txt           text
*.vcproj        text eol=crlf
*.sh            text eol=lf
*.jpg           -text</screen>
<note><simpara>When <emphasis>text=auto</emphasis> conversion is enabled in a cross-platform
project using push and pull to a central repository the text files
containing CRLFs should be normalized.</simpara></note>
<simpara>From a clean working directory:</simpara>
<screen>$ echo "* text=auto" &gt;.gitattributes
$ git add --renormalize .
$ git status        # Show files that will be normalized
$ git commit -m "Introduce end-of-line normalization"</screen>
<simpara>If any files that should not be normalized show up in <emphasis>git status</emphasis>,
unset their <emphasis>text</emphasis> attribute before running <emphasis>git add -u</emphasis>.</simpara>
<screen>manual.pdf      -text</screen>
<simpara>Conversely, text files that Git does not detect can have normalization
enabled manually.</simpara>
<screen>weirdchars.txt  text</screen>
<simpara>If <emphasis>core.safecrlf</emphasis> is set to "true" or "warn", Git verifies if
the conversion is reversible for the current setting of
<emphasis>core.autocrlf</emphasis>.  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>
</section>
<section id="gitattributes(5)__emphasis_working_tree_encoding_emphasis">
<title><emphasis>working-tree-encoding</emphasis></title>
<simpara>Git recognizes files encoded in ASCII or one of its supersets (e.g.
UTF-8, ISO-8859-1, &#8230;) as text files. Files encoded in certain other
encodings (e.g. UTF-16) are interpreted as binary and consequently
built-in Git text processing tools (e.g. <emphasis>git diff</emphasis>) as well as most Git
web front ends do not visualize the contents of these files by default.</simpara>
<simpara>In these cases you can tell Git the encoding of a file in the working
directory with the <emphasis>working-tree-encoding</emphasis> attribute. If a file with this
attribute is added to Git, then Git re-encodes the content from the
specified encoding to UTF-8. Finally, Git stores the UTF-8 encoded
content in its internal data structure (called "the index"). On checkout
the content is re-encoded back to the specified encoding.</simpara>
<simpara>Please note that using the <emphasis>working-tree-encoding</emphasis> attribute may have a
number of pitfalls:</simpara>
<itemizedlist>
<listitem>
<simpara>
Alternative Git implementations (e.g. JGit or libgit2) and older Git
  versions (as of March 2018) do not support the <emphasis>working-tree-encoding</emphasis>
  attribute. If you decide to use the <emphasis>working-tree-encoding</emphasis> attribute
  in your repository, then it is strongly recommended to ensure that all
  clients working with the repository support it.
</simpara>
<simpara>For example, Microsoft Visual Studio resources files (<emphasis>*.rc</emphasis>) or
PowerShell script files (<emphasis>*.ps1</emphasis>) are sometimes encoded in UTF-16.
If you declare <emphasis>*.ps1</emphasis> as files as UTF-16 and you add <emphasis>foo.ps1</emphasis> with
a <emphasis>working-tree-encoding</emphasis> enabled Git client, then <emphasis>foo.ps1</emphasis> will be
stored as UTF-8 internally. A client without <emphasis>working-tree-encoding</emphasis>
support will checkout <emphasis>foo.ps1</emphasis> as UTF-8 encoded file. This will
typically cause trouble for the users of this file.</simpara>
<simpara>If a Git client that does not support the <emphasis>working-tree-encoding</emphasis>
attribute adds a new file <emphasis>bar.ps1</emphasis>, then <emphasis>bar.ps1</emphasis> will be
stored "as-is" internally (in this example probably as UTF-16).
A client with <emphasis>working-tree-encoding</emphasis> support will interpret the
internal contents as UTF-8 and try to convert it to UTF-16 on checkout.
That operation will fail and cause an error.</simpara>
</listitem>
<listitem>
<simpara>
Reencoding content to non-UTF encodings can cause errors as the
  conversion might not be UTF-8 round trip safe. If you suspect your
  encoding to not be round trip safe, then add it to
  <emphasis>core.checkRoundtripEncoding</emphasis> to make Git check the round trip
  encoding (see <xref linkend="git-config(1)" />). SHIFT-JIS (Japanese character
  set) is known to have round trip issues with UTF-8 and is checked by
  default.
</simpara>
</listitem>
<listitem>
<simpara>
Reencoding content requires resources that might slow down certain
  Git operations (e.g <emphasis>git checkout</emphasis> or <emphasis>git add</emphasis>).
</simpara>
</listitem>
</itemizedlist>
<simpara>Use the <emphasis>working-tree-encoding</emphasis> attribute only if you cannot store a file
in UTF-8 encoding and if you want Git to be able to process the content
as text.</simpara>
<simpara>As an example, use the following attributes if your <emphasis>*.ps1</emphasis> files are
UTF-16 encoded with byte order mark (BOM) and you want Git to perform
automatic line ending conversion based on your platform.</simpara>
<screen>*.ps1           text working-tree-encoding=UTF-16</screen>
<simpara>Use the following attributes if your <emphasis>*.ps1</emphasis> files are UTF-16 little
endian encoded without BOM and you want Git to use Windows line endings
in the working directory (use <emphasis>UTF-16LE-BOM</emphasis> instead of <emphasis>UTF-16LE</emphasis> if
you want UTF-16 little endian with BOM).
Please note, it is highly recommended to
explicitly define the line endings with <emphasis>eol</emphasis> if the <emphasis>working-tree-encoding</emphasis>
attribute is used to avoid ambiguity.</simpara>
<screen>*.ps1           text working-tree-encoding=UTF-16LE eol=CRLF</screen>
<simpara>You can get a list of all available encodings on your platform with the
following command:</simpara>
<screen>iconv --list</screen>
<simpara>If you do not know the encoding of a file, then you can use the <emphasis>file</emphasis>
command to guess the encoding:</simpara>
<screen>file foo.ps1</screen>
</section>
<section id="gitattributes(5)__emphasis_ident_emphasis">
<title><emphasis>ident</emphasis></title>
<simpara>When the attribute <emphasis>ident</emphasis> is set for a path, Git replaces
<emphasis>$Id$</emphasis> in the blob object with <emphasis>$Id:</emphasis>, followed by the
40-character hexadecimal blob object name, followed by a dollar
sign <emphasis>$</emphasis> upon checkout.  Any byte sequence that begins with
<emphasis>$Id:</emphasis> and ends with <emphasis>$</emphasis> in the worktree file is replaced
with <emphasis>$Id$</emphasis> upon check-in.</simpara>
</section>
<section id="gitattributes(5)__emphasis_filter_emphasis">
<title><emphasis>filter</emphasis></title>
<simpara>A <emphasis>filter</emphasis> 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 <emphasis>clean</emphasis> command and a <emphasis>smudge</emphasis>
command, either of which can be left unspecified.  Upon
checkout, when the <emphasis>smudge</emphasis> 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
<emphasis>clean</emphasis> command is used to convert the contents of worktree file
upon checkin. By default these commands process only a single
blob and terminate. If a long running <emphasis>process</emphasis> filter is used
in place of <emphasis>clean</emphasis> and/or <emphasis>smudge</emphasis> filters, then Git can process
all blobs with a single filter command invocation for the entire
life of a single Git command, for example <emphasis>git add --all</emphasis>. If a
long running <emphasis>process</emphasis> filter is configured then it always takes
precedence over a configured single blob filter. See section
below for the description of the protocol used to communicate with
a <emphasis>process</emphasis> filter.</simpara>
<simpara>One use of the content filtering is to massage the content into a shape
that is more convenient for the platform, filesystem, and the user to use.
For this mode of operation, 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>
<simpara>Another use of the content filtering is to store the content that cannot
be directly used in the repository (e.g. a UUID that refers to the true
content stored outside Git, or an encrypted content) and turn it into a
usable form upon checkout (e.g. download the external content, or decrypt
the encrypted content).</simpara>
<simpara>These two filters behave differently, and by default, a filter is taken as
the former, massaging the contents into more convenient shape.  A missing
filter driver definition in the config, or a filter driver that exits with
a non-zero status, is not an error but makes the filter a no-op passthru.</simpara>
<simpara>You can declare that a filter turns a content that by itself is unusable
into a usable content by setting the filter.&lt;driver&gt;.required configuration
variable to <emphasis>true</emphasis>.</simpara>
<simpara>Note: Whenever the clean filter is changed, the repo should be renormalized:
$ git add --renormalize .</simpara>
<simpara>For example, in .gitattributes, you would assign the <emphasis>filter</emphasis>
attribute for paths.</simpara>
<screen>*.c     filter=indent</screen>
<simpara>Then you would define a "filter.indent.clean" and "filter.indent.smudge"
configuration in your .git/config to specify a pair of commands to
modify the contents of C programs when the source files are checked
in ("clean" is run) and checked out (no change is made because the
command is "cat").</simpara>
<screen>[filter "indent"]
        clean = indent
        smudge = cat</screen>
<simpara>For best results, <emphasis>clean</emphasis> should not alter its output further if it is
run twice ("clean&#8594;clean" should be equivalent to "clean"), and
multiple <emphasis>smudge</emphasis> commands should not alter <emphasis>clean</emphasis>'s output
("smudge&#8594;smudge&#8594;clean" should be equivalent to "clean").  See the
section on merging below.</simpara>
<simpara>The "indent" filter is well-behaved in this regard: it will not modify
input that is already correctly indented.  In this case, the lack of a
smudge filter means that the clean filter <emphasis>must</emphasis> accept its own output
without modifying it.</simpara>
<simpara>If a filter <emphasis>must</emphasis> succeed in order to make the stored contents usable,
you can declare that the filter is <emphasis>required</emphasis>, in the configuration:</simpara>
<screen>[filter "crypt"]
        clean = openssl enc ...
        smudge = openssl enc -d ...
        required</screen>
<simpara>Sequence "%f" on the filter command line is replaced with the name of
the file the filter is working on.  A filter might use this in keyword
substitution.  For example:</simpara>
<screen>[filter "p4"]
        clean = git-p4-filter --clean %f
        smudge = git-p4-filter --smudge %f</screen>
<simpara>Note that "%f" is the name of the path that is being worked on. Depending
on the version that is being filtered, the corresponding file on disk may
not exist, or may have different contents. So, smudge and clean commands
should not try to access the file on disk, but only act as filters on the
content provided to them on standard input.</simpara>
</section>
<section id="gitattributes(5)__long_running_filter_process">
<title>Long Running Filter Process</title>
<simpara>If the filter command (a string value) is defined via
<emphasis>filter.&lt;driver&gt;.process</emphasis> then Git can process all blobs with a
single filter invocation for the entire life of a single Git
command. This is achieved by using the long-running process protocol
(described in technical/long-running-process-protocol.txt).</simpara>
<simpara>When Git encounters the first file that needs to be cleaned or smudged,
it starts the filter and performs the handshake. In the handshake, the
welcome message sent by Git is "git-filter-client", only version 2 is
supported, and the supported capabilities are "clean", "smudge", and
"delay".</simpara>
<simpara>Afterwards Git sends a list of "key=value" pairs terminated with
a flush packet. The list will contain at least the filter command
(based on the supported capabilities) and the pathname of the file
to filter relative to the repository root. Right after the flush packet
Git sends the content split in zero or more pkt-line packets and a
flush packet to terminate content. Please note, that the filter
must not send any response before it received the content and the
final flush packet. Also note that the "value" of a "key=value" pair
can contain the "=" character whereas the key would never contain
that character.</simpara>
<screen>packet:          git&gt; command=smudge
packet:          git&gt; pathname=path/testfile.dat
packet:          git&gt; 0000
packet:          git&gt; CONTENT
packet:          git&gt; 0000</screen>
<simpara>The filter is expected to respond with a list of "key=value" pairs
terminated with a flush packet. If the filter does not experience
problems then the list must contain a "success" status. Right after
these packets the filter is expected to send the content in zero
or more pkt-line packets and a flush packet at the end. Finally, a
second list of "key=value" pairs terminated with a flush packet
is expected. The filter can change the status in the second list
or keep the status as is with an empty list. Please note that the
empty list must be terminated with a flush packet regardless.</simpara>
<screen>packet:          git&lt; status=success
packet:          git&lt; 0000
packet:          git&lt; SMUDGED_CONTENT
packet:          git&lt; 0000
packet:          git&lt; 0000  # empty list, keep "status=success" unchanged!</screen>
<simpara>If the result content is empty then the filter is expected to respond
with a "success" status and a flush packet to signal the empty content.</simpara>
<screen>packet:          git&lt; status=success
packet:          git&lt; 0000
packet:          git&lt; 0000  # empty content!
packet:          git&lt; 0000  # empty list, keep "status=success" unchanged!</screen>
<simpara>In case the filter cannot or does not want to process the content,
it is expected to respond with an "error" status.</simpara>
<screen>packet:          git&lt; status=error
packet:          git&lt; 0000</screen>
<simpara>If the filter experiences an error during processing, then it can
send the status "error" after the content was (partially or
completely) sent.</simpara>
<screen>packet:          git&lt; status=success
packet:          git&lt; 0000
packet:          git&lt; HALF_WRITTEN_ERRONEOUS_CONTENT
packet:          git&lt; 0000
packet:          git&lt; status=error
packet:          git&lt; 0000</screen>
<simpara>In case the filter cannot or does not want to process the content
as well as any future content for the lifetime of the Git process,
then it is expected to respond with an "abort" status at any point
in the protocol.</simpara>
<screen>packet:          git&lt; status=abort
packet:          git&lt; 0000</screen>
<simpara>Git neither stops nor restarts the filter process in case the
"error"/"abort" status is set. However, Git sets its exit code
according to the <emphasis>filter.&lt;driver&gt;.required</emphasis> flag, mimicking the
behavior of the <emphasis>filter.&lt;driver&gt;.clean</emphasis> / <emphasis>filter.&lt;driver&gt;.smudge</emphasis>
mechanism.</simpara>
<simpara>If the filter dies during the communication or does not adhere to
the protocol then Git will stop the filter process and restart it
with the next file that needs to be processed. Depending on the
<emphasis>filter.&lt;driver&gt;.required</emphasis> flag Git will interpret that as error.</simpara>
</section>
<section id="gitattributes(5)__delay">
<title>Delay</title>
<simpara>If the filter supports the "delay" capability, then Git can send the
flag "can-delay" after the filter command and pathname. This flag
denotes that the filter can delay filtering the current blob (e.g. to
compensate network latencies) by responding with no content but with
the status "delayed" and a flush packet.</simpara>
<screen>packet:          git&gt; command=smudge
packet:          git&gt; pathname=path/testfile.dat
packet:          git&gt; can-delay=1
packet:          git&gt; 0000
packet:          git&gt; CONTENT
packet:          git&gt; 0000
packet:          git&lt; status=delayed
packet:          git&lt; 0000</screen>
<simpara>If the filter supports the "delay" capability then it must support the
"list_available_blobs" command. If Git sends this command, then the
filter is expected to return a list of pathnames representing blobs
that have been delayed earlier and are now available.
The list must be terminated with a flush packet followed
by a "success" status that is also terminated with a flush packet. If
no blobs for the delayed paths are available, yet, then the filter is
expected to block the response until at least one blob becomes
available. The filter can tell Git that it has no more delayed blobs
by sending an empty list. As soon as the filter responds with an empty
list, Git stops asking. All blobs that Git has not received at this
point are considered missing and will result in an error.</simpara>
<screen>packet:          git&gt; command=list_available_blobs
packet:          git&gt; 0000
packet:          git&lt; pathname=path/testfile.dat
packet:          git&lt; pathname=path/otherfile.dat
packet:          git&lt; 0000
packet:          git&lt; status=success
packet:          git&lt; 0000</screen>
<simpara>After Git received the pathnames, it will request the corresponding
blobs again. These requests contain a pathname and an empty content
section. The filter is expected to respond with the smudged content
in the usual way as explained above.</simpara>
<screen>packet:          git&gt; command=smudge
packet:          git&gt; pathname=path/testfile.dat
packet:          git&gt; 0000
packet:          git&gt; 0000  # empty content!
packet:          git&lt; status=success
packet:          git&lt; 0000
packet:          git&lt; SMUDGED_CONTENT
packet:          git&lt; 0000
packet:          git&lt; 0000  # empty list, keep "status=success" unchanged!</screen>
</section>
<section id="gitattributes(5)__example">
<title>Example</title>
<simpara>A long running filter demo implementation can be found in
<emphasis>contrib/long-running-filter/example.pl</emphasis> located in the Git
core repository. If you develop your own long running filter
process then the <emphasis>GIT_TRACE_PACKET</emphasis> environment variables can be
very helpful for debugging (see <xref linkend="git(1)" />).</simpara>
<simpara>Please note that you cannot use an existing <emphasis>filter.&lt;driver&gt;.clean</emphasis>
or <emphasis>filter.&lt;driver&gt;.smudge</emphasis> command with <emphasis>filter.&lt;driver&gt;.process</emphasis>
because the former two use a different inter process communication
protocol than the latter one.</simpara>
</section>
<section id="gitattributes(5)__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 <emphasis>filter</emphasis> driver (if specified and corresponding driver
defined), then the result is processed with <emphasis>ident</emphasis> (if
specified), and then finally with <emphasis>text</emphasis> (again, if specified
and applicable).</simpara>
<simpara>In the check-out codepath, the blob content is first converted
with <emphasis>text</emphasis>, and then <emphasis>ident</emphasis> and fed to <emphasis>filter</emphasis>.</simpara>
</section>
<section id="gitattributes(5)__merging_branches_with_differing_checkin_checkout_attributes">
<title>Merging branches with differing checkin/checkout attributes</title>
<simpara>If you have added attributes to a file that cause the canonical
repository format for that file to change, such as adding a
clean/smudge filter or text/eol/ident attributes, merging anything
where the attribute is not in place would normally cause merge
conflicts.</simpara>
<simpara>To prevent these unnecessary merge conflicts, Git can be told to run a
virtual check-out and check-in of all three stages of a file when
resolving a three-way merge by setting the <emphasis>merge.renormalize</emphasis>
configuration variable.  This prevents changes caused by check-in
conversion from causing spurious merge conflicts when a converted file
is merged with an unconverted file.</simpara>
<simpara>As long as a "smudge&#8594;clean" results in the same output as a "clean"
even on files that are already smudged, this strategy will
automatically resolve all filter-related conflicts.  Filters that do
not act in this way may cause additional merge conflicts that must be
resolved manually.</simpara>
</section>
</section>
<section id="gitattributes(5)__generating_diff_text">
<title>Generating diff text</title>
<section id="gitattributes(5)__emphasis_diff_emphasis">
<title><emphasis>diff</emphasis></title>
<simpara>The attribute <emphasis>diff</emphasis> affects how Git 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 <emphasis>@@ -k,l +n,m @@</emphasis> 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 <emphasis>diff</emphasis> 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 <emphasis>diff</emphasis> attribute is unset will
        generate <emphasis>Binary files differ</emphasis> (or a binary patch, if
        binary patches are enabled).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
Unspecified
</term>
<listitem>
<simpara>
        A path to which the <emphasis>diff</emphasis> attribute is unspecified
        first gets its contents inspected, and if it looks like
        text and is smaller than core.bigFileThreshold, it is treated
        as text. Otherwise it would generate <emphasis>Binary files differ</emphasis>.
</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>
</section>
<section id="gitattributes(5)__defining_an_external_diff_driver">
<title>Defining an external diff driver</title>
<simpara>The definition of a diff driver is done in <emphasis>gitconfig</emphasis>, not
<emphasis>gitattributes</emphasis> 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 <emphasis>jcdiff</emphasis>, add a section to your
<emphasis>$GIT_DIR/config</emphasis> file (or <emphasis>$HOME/.gitconfig</emphasis> file) like this:</simpara>
<screen>[diff "jcdiff"]
        command = j-c-diff</screen>
<simpara>When Git needs to show you a diff for the path with <emphasis>diff</emphasis>
attribute set to <emphasis>jcdiff</emphasis>, it calls the command you specified
with the above configuration, i.e. <emphasis>j-c-diff</emphasis>, with 7
parameters, just like <emphasis>GIT_EXTERNAL_DIFF</emphasis> program is called.
See <xref linkend="git(1)" /> for details.</simpara>
</section>
<section id="gitattributes(5)__setting_the_internal_diff_algorithm">
<title>Setting the internal diff algorithm</title>
<simpara>The diff algorithm can be set through the <emphasis>diff.algorithm</emphasis> config key, but
sometimes it may be helpful to set the diff algorithm per path. For example,
one may want to use the <emphasis>minimal</emphasis> diff algorithm for .json files, and the
<emphasis>histogram</emphasis> for .c files, and so on without having to pass in the algorithm
through the command line each time.</simpara>
<simpara>First, in <emphasis>.gitattributes</emphasis>, assign the <emphasis>diff</emphasis> attribute for paths.</simpara>
<screen>*.json diff=&lt;name&gt;</screen>
<simpara>Then, define a "diff.&lt;name&gt;.algorithm" configuration to specify the diff
algorithm, choosing from <emphasis>myers</emphasis>, <emphasis>patience</emphasis>, <emphasis>minimal</emphasis>, or <emphasis>histogram</emphasis>.</simpara>
<screen>[diff "&lt;name&gt;"]
  algorithm = histogram</screen>
<simpara>This diff algorithm applies to user facing diff output like git-diff(1),
git-show(1) and is used for the <emphasis>--stat</emphasis> output as well. The merge machinery
will not use the diff algorithm set through this method.</simpara>
<note><simpara>If <emphasis>diff.&lt;name&gt;.command</emphasis> is defined for path with the
<emphasis>diff=&lt;name&gt;</emphasis> attribute, it is executed as an external diff driver
(see above), and adding <emphasis>diff.&lt;name&gt;.algorithm</emphasis> has no effect, as the
algorithm is not passed to the external diff driver.</simpara></note>
</section>
<section id="gitattributes(5)__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 <emphasis>diff</emphasis> attribute
for paths.</simpara>
<screen>*.tex   diff=tex</screen>
<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". Add a section to your
<emphasis>$GIT_DIR/config</emphasis> file (or <emphasis>$HOME/.gitconfig</emphasis> file) like this:</simpara>
<screen>[diff "tex"]
        xfuncname = "^(\\\\(sub)*section\\{.*)$"</screen>
<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 <emphasis>sub</emphasis> followed by
<emphasis>section</emphasis> followed by open brace, to the end of line.</simpara>
<simpara>There are a few built-in patterns to make this easier, and <emphasis>tex</emphasis>
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 <emphasis>.gitattributes</emphasis>).  The following built in
patterns are available:</simpara>
<itemizedlist>
<listitem>
<simpara>
<emphasis>ada</emphasis> suitable for source code in the Ada language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>bash</emphasis> suitable for source code in the Bourne-Again SHell language.
  Covers a superset of POSIX shell function definitions.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>bibtex</emphasis> suitable for files with BibTeX coded references.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>cpp</emphasis> suitable for source code in the C and C++ languages.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>csharp</emphasis> suitable for source code in the C# language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>css</emphasis> suitable for cascading style sheets.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>dts</emphasis> suitable for devicetree (DTS) files.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>elixir</emphasis> suitable for source code in the Elixir language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>fortran</emphasis> suitable for source code in the Fortran language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>fountain</emphasis> suitable for Fountain documents.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>golang</emphasis> suitable for source code in the Go language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>html</emphasis> suitable for HTML/XHTML documents.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>java</emphasis> suitable for source code in the Java language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>kotlin</emphasis> suitable for source code in the Kotlin language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>markdown</emphasis> suitable for Markdown documents.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>matlab</emphasis> suitable for source code in the MATLAB and Octave languages.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>objc</emphasis> suitable for source code in the Objective-C language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>pascal</emphasis> suitable for source code in the Pascal/Delphi language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>perl</emphasis> suitable for source code in the Perl language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>php</emphasis> suitable for source code in the PHP language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>python</emphasis> suitable for source code in the Python language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>ruby</emphasis> suitable for source code in the Ruby language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>rust</emphasis> suitable for source code in the Rust language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>scheme</emphasis> suitable for source code in the Scheme language.
</simpara>
</listitem>
<listitem>
<simpara>
<emphasis>tex</emphasis> suitable for source code for LaTeX documents.
</simpara>
</listitem>
</itemizedlist>
</section>
<section id="gitattributes(5)__customizing_word_diff">
<title>Customizing word diff</title>
<simpara>You can customize the rules that <emphasis>git diff --word-diff</emphasis> 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 in your
<emphasis>$GIT_DIR/config</emphasis> file (or <emphasis>$HOME/.gitconfig</emphasis> file) like this:</simpara>
<screen>[diff "tex"]
        wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"</screen>
<simpara>A built-in pattern is provided for all languages listed in the
previous section.</simpara>
</section>
<section id="gitattributes(5)__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 <emphasis>textconv</emphasis> 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), add the following section to your
<emphasis>$GIT_DIR/config</emphasis> file (or <emphasis>$HOME/.gitconfig</emphasis> file):</simpara>
<screen>[diff "jpg"]
        textconv = exif</screen>
<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 <emphasis>git diff</emphasis> and the <emphasis>git log</emphasis> family of commands (i.e.,
log, whatchanged, show) will perform text conversion. <emphasis>git
format-patch</emphasis> 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>
<simpara>Because text conversion can be slow, especially when doing a
large number of them with <emphasis>git log -p</emphasis>, Git provides a mechanism
to cache the output and use it in future diffs.  To enable
caching, set the "cachetextconv" variable in your diff driver's
config. For example:</simpara>
<screen>[diff "jpg"]
        textconv = exif
        cachetextconv = true</screen>
<simpara>This will cache the result of running "exif" on each blob
indefinitely. If you change the textconv config variable for a
diff driver, Git will automatically invalidate the cache entries
and re-run the textconv filter. If you want to invalidate the
cache manually (e.g., because your version of "exif" was updated
and now produces better output), you can remove the cache
manually with <emphasis>git update-ref -d refs/notes/textconv/jpg</emphasis> (where
"jpg" is the name of the diff driver, as in the example above).</simpara>
</section>
<section id="gitattributes(5)__choosing_textconv_versus_external_diff">
<title>Choosing textconv versus external diff</title>
<simpara>If you want to show differences between binary or specially-formatted
blobs in your repository, you can choose to use either an external diff
command, or to use textconv to convert them to a diff-able text format.
Which method you choose depends on your exact situation.</simpara>
<simpara>The advantage of using an external diff command is flexibility. You are
not bound to find line-oriented changes, nor is it necessary for the
output to resemble unified diff. You are free to locate and report
changes in the most appropriate way for your data format.</simpara>
<simpara>A textconv, by comparison, is much more limiting. You provide a
transformation of the data into a line-oriented text format, and Git
uses its regular diff tools to generate the output. There are several
advantages to choosing this method:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
Ease of use. It is often much simpler to write a binary to text
   transformation than it is to perform your own diff. In many cases,
   existing programs can be used as textconv filters (e.g., exif,
   odt2txt).
</simpara>
</listitem>
<listitem>
<simpara>
Git diff features. By performing only the transformation step
   yourself, you can still utilize many of Git's diff features,
   including colorization, word-diff, and combined diffs for merges.
</simpara>
</listitem>
<listitem>
<simpara>
Caching. Textconv caching can speed up repeated diffs, such as those
   you might trigger by running <emphasis>git log -p</emphasis>.
</simpara>
</listitem>
</orderedlist>
</section>
<section id="gitattributes(5)__marking_files_as_binary">
<title>Marking files as binary</title>
<simpara>Git usually guesses correctly whether a blob contains text or binary
data by examining the beginning of the contents. However, sometimes you
may want to override its decision, either because a blob contains binary
data later in the file, or because the content, while technically
composed of text characters, is opaque to a human reader. For example,
many postscript files contain only ASCII characters, but produce noisy
and meaningless diffs.</simpara>
<simpara>The simplest way to mark a file as binary is to unset the diff
attribute in the <emphasis>.gitattributes</emphasis> file:</simpara>
<screen>*.ps -diff</screen>
<simpara>This will cause Git to generate <emphasis>Binary files differ</emphasis> (or a binary
patch, if binary patches are enabled) instead of a regular diff.</simpara>
<simpara>However, one may also want to specify other diff driver attributes. For
example, you might want to use <emphasis>textconv</emphasis> to convert postscript files to
an ASCII representation for human viewing, but otherwise treat them as
binary files. You cannot specify both <emphasis>-diff</emphasis> and <emphasis>diff=ps</emphasis> attributes.
The solution is to use the <emphasis>diff.*.binary</emphasis> config option:</simpara>
<screen>[diff "ps"]
  textconv = ps2ascii
  binary = true</screen>
</section>
</section>
<section id="gitattributes(5)__performing_a_three_way_merge">
<title>Performing a three-way merge</title>
<section id="gitattributes(5)__emphasis_merge_emphasis">
<title><emphasis>merge</emphasis></title>
<simpara>The attribute <emphasis>merge</emphasis> affects how three versions of a file are
merged when a file-level merge is necessary during <emphasis>git merge</emphasis>,
and other commands such as <emphasis>git revert</emphasis> and <emphasis>git cherry-pick</emphasis>.</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 <emphasis>RCS</emphasis>
        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 do
        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 when the <emphasis>merge</emphasis> attribute is set.
        However, the <emphasis>merge.default</emphasis> configuration variable can name
        different merge driver to be used with paths for which the
        <emphasis>merge</emphasis> 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>
</section>
<section id="gitattributes(5)__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 <emphasis>merge</emphasis> 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 <emphasis>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</emphasis>,
        <emphasis>=======</emphasis> and <emphasis>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</emphasis>.  The version from your branch
        appears before the <emphasis>=======</emphasis> marker, and the version
        from the merged branch appears after the <emphasis>=======</emphasis>
        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>
</section>
<section id="gitattributes(5)__defining_a_custom_merge_driver">
<title>Defining a custom merge driver</title>
<simpara>The definition of a merge driver is done in the <emphasis>.git/config</emphasis>
file, not in the <emphasis>gitattributes</emphasis> 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 <emphasis>filfre</emphasis>, add a section to your
<emphasis>$GIT_DIR/config</emphasis> file (or <emphasis>$HOME/.gitconfig</emphasis> file) like this:</simpara>
<screen>[merge "filfre"]
        name = feel-free merge driver
        driver = filfre %O %A %B %L %P
        recursive = binary</screen>
<simpara>The <emphasis>merge.*.name</emphasis> variable gives the driver a human-readable
name.</simpara>
<simpara>The merge.*.driver` variable's value is used to construct a
command to run to common ancestor's version (<emphasis>%O</emphasis>), current
version (<emphasis>%A</emphasis>) and the other branches version (<emphasis>%B</emphasis>).  These
three tokens are replaced with the names of temporary files that
hold the contents of these versions when the command line is
built. Additionally, <emphasis>%L</emphasis> will be replaced with the conflict marker
size (see below).</simpara>
<simpara>The merge driver is expected to leave the result of the merge in
the file named with <emphasis>%A</emphasis> by overwriting it, and exit with zero
status if it managed to merge them cleanly, or non-zero if there
were conflicts.  When the driver crashes (e.g. killed by SEGV),
it is expected to exit with non-zero status that are higher than
128, and in such a case, the merge results in a failure (which is
different from producing a conflict).</simpara>
<simpara>The <emphasis>merge.*.recursive</emphasis> 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>
<simpara>The merge driver can learn the pathname in which the merged result
will be stored via placeholder <emphasis>%P</emphasis>. The conflict labels to be used
for the common ancestor, local head and other head can be passed by
using <emphasis>%S</emphasis>, <emphasis>%X</emphasis> and '%Y` respectively.</simpara>
</section>
<section id="gitattributes(5)__emphasis_conflict_marker_size_emphasis">
<title><emphasis>conflict-marker-size</emphasis></title>
<simpara>This attribute controls the length of conflict markers left in
the work tree file during a conflicted merge.  Only a positive
integer has a meaningful effect.</simpara>
<simpara>For example, this line in <emphasis>.gitattributes</emphasis> can be used to tell the merge
machinery to leave much longer (instead of the usual 7-character-long)
conflict markers when merging the file <emphasis>Documentation/git-merge.txt</emphasis>
results in a conflict.</simpara>
<screen>Documentation/git-merge.txt     conflict-marker-size=32</screen>
</section>
</section>
<section id="gitattributes(5)__checking_whitespace_errors">
<title>Checking whitespace errors</title>
<section id="gitattributes(5)__emphasis_whitespace_emphasis">
<title><emphasis>whitespace</emphasis></title>
<simpara>The <emphasis>core.whitespace</emphasis> 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.
        The tab width is taken from the value of the <emphasis>core.whitespace</emphasis>
        configuration variable.
</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 the <emphasis>core.whitespace</emphasis> configuration variable to
        decide what to notice as error.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
String
</term>
<listitem>
<simpara>
        Specify a comma separated list of common whitespace problems to
        notice in the same format as the <emphasis>core.whitespace</emphasis> configuration
        variable.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</section>
</section>
<section id="gitattributes(5)__creating_an_archive">
<title>Creating an archive</title>
<section id="gitattributes(5)__emphasis_export_ignore_emphasis">
<title><emphasis>export-ignore</emphasis></title>
<simpara>Files and directories with the attribute <emphasis>export-ignore</emphasis> won't be added to
archive files.</simpara>
</section>
<section id="gitattributes(5)__emphasis_export_subst_emphasis">
<title><emphasis>export-subst</emphasis></title>
<simpara>If the attribute <emphasis>export-subst</emphasis> 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 <emphasis>--pretty=format:</emphasis> of <xref linkend="git-log(1)" />,
except that they need to be wrapped like this: <emphasis>$Format:PLACEHOLDERS$</emphasis>
in the file.  E.g. the string <emphasis>$Format:%H$</emphasis> will be replaced by the
commit hash.  However, only one <emphasis>%(describe)</emphasis> placeholder is expanded
per archive to avoid denial-of-service attacks.</simpara>
</section>
</section>
<section id="gitattributes(5)__packing_objects">
<title>Packing objects</title>
<section id="gitattributes(5)__emphasis_delta_emphasis">
<title><emphasis>delta</emphasis></title>
<simpara>Delta compression will not be attempted for blobs for paths with the
attribute <emphasis>delta</emphasis> set to false.</simpara>
</section>
</section>
<section id="gitattributes(5)__viewing_files_in_gui_tools">
<title>Viewing files in GUI tools</title>
<section id="gitattributes(5)__emphasis_encoding_emphasis">
<title><emphasis>encoding</emphasis></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
<emphasis>gui.encoding</emphasis> configuration variable is used instead
(See <xref linkend="git-config(1)" />).</simpara>
</section>
</section>
</simplesect>
<simplesect id="gitattributes(5)__using_macro_attributes">
<title>USING MACRO ATTRIBUTES</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>
<screen>*.jpg -text -diff</screen>
<simpara>but that may become cumbersome, when you have many attributes.  Using
macro attributes, you can define an attribute that, when set, also
sets or unsets a number of other attributes at the same time.  The
system knows a built-in macro attribute, <emphasis>binary</emphasis>:</simpara>
<screen>*.jpg binary</screen>
<simpara>Setting the "binary" attribute also unsets the "text" and "diff"
attributes as above.  Note that macro attributes can only be "Set",
though setting one might have the effect of setting or unsetting other
attributes or even returning other attributes to the "Unspecified"
state.</simpara>
</simplesect>
<simplesect id="gitattributes(5)__defining_macro_attributes">
<title>DEFINING MACRO ATTRIBUTES</title>
<simpara>Custom macro attributes can be defined only in top-level gitattributes
files (<emphasis>$GIT_DIR/info/attributes</emphasis>, the <emphasis>.gitattributes</emphasis> file at the
top level of the working tree, or the global or system-wide
gitattributes files), not in <emphasis>.gitattributes</emphasis> files in working tree
subdirectories.  The built-in macro attribute "binary" is equivalent
to:</simpara>
<screen>[attr]binary -diff -merge -text</screen>
</simplesect>
<simplesect id="gitattributes(5)__notes">
<title>NOTES</title>
<simpara>Git does not follow symbolic links when accessing a <emphasis>.gitattributes</emphasis>
file in the working tree. This keeps behavior consistent when the file
is accessed from the index or a tree versus from the filesystem.</simpara>
</simplesect>
<simplesect id="gitattributes(5)__examples">
<title>EXAMPLES</title>
<simpara>If you have these three <emphasis>gitattributes</emphasis> file:</simpara>
<screen>(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</screen>
<simpara>the attributes given to path <emphasis>t/abc</emphasis> are computed as follows:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
By examining <emphasis>t/.gitattributes</emphasis> (which is in the same
   directory as the path in question), Git finds that the first
   line matches.  <emphasis>merge</emphasis> attribute is set.  It also finds that
   the second line matches, and attributes <emphasis>foo</emphasis> and <emphasis>bar</emphasis>
   are unset.
</simpara>
</listitem>
<listitem>
<simpara>
Then it examines <emphasis>.gitattributes</emphasis> (which is in the parent
   directory), and finds that the first line matches, but
   <emphasis>t/.gitattributes</emphasis> file already decided how <emphasis>merge</emphasis>, <emphasis>foo</emphasis>
   and <emphasis>bar</emphasis> attributes should be given to this path, so it
   leaves <emphasis>foo</emphasis> and <emphasis>bar</emphasis> unset.  Attribute <emphasis>baz</emphasis> is set.
</simpara>
</listitem>
<listitem>
<simpara>
Finally it examines <emphasis>$GIT_DIR/info/attributes</emphasis>.  This file
   is used to override the in-tree settings.  The first line is
   a match, and <emphasis>foo</emphasis> is set, <emphasis>bar</emphasis> is reverted to unspecified
   state, and <emphasis>baz</emphasis> is unset.
</simpara>
</listitem>
</orderedlist>
<simpara>As the result, the attributes assignment to <emphasis>t/abc</emphasis> becomes:</simpara>
<screen>foo     set to true
bar     unspecified
baz     set to false
merge   set to string value "filfre"
frotz   unspecified</screen>
</simplesect>
<simplesect id="gitattributes(5)__see_also">
<title>SEE ALSO</title>
<simpara><xref linkend="git-check-attr(1)" />.</simpara>
</simplesect>
<simplesect id="gitattributes(5)__git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
</simplesect>
</sect2>
