Updated git_doc to git 1.8
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / gitattributes.xml
bloba6678a7f7d306fb5325aa05d34d61c18c052cbd4
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE sect2 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <sect2 lang="en" id="gitattributes(5)">\r
5     <title>gitattributes(5)</title>\r
6 <indexterm>\r
7 <primary>gitattributes(5)</primary>\r
8 </indexterm>\r
9 <simplesect id="gitattributes(5)__name">\r
10 <title>NAME</title>\r
11 <simpara>gitattributes - defining attributes per path</simpara>\r
12 </simplesect>\r
13 <simplesect id="gitattributes(5)__synopsis">\r
14 <title>SYNOPSIS</title>\r
15 <simpara>$GIT_DIR/info/attributes, .gitattributes</simpara>\r
16 </simplesect>\r
17 <simplesect id="gitattributes(5)__description">\r
18 <title>DESCRIPTION</title>\r
19 <simpara>A <emphasis>gitattributes</emphasis> file is a simple text file that gives\r
20 <emphasis>attributes</emphasis> to pathnames.</simpara>\r
21 <simpara>Each line in <emphasis>gitattributes</emphasis> file is of form:</simpara>\r
22 <literallayout class="monospaced">pattern attr1 attr2 ...</literallayout>\r
23 <simpara>That is, a pattern followed by an attributes list,\r
24 separated by whitespaces.  When the pattern matches the\r
25 path in question, the attributes listed on the line are given to\r
26 the path.</simpara>\r
27 <simpara>Each attribute can be in one of these states for a given path:</simpara>\r
28 <variablelist>\r
29 <varlistentry>\r
30 <term>\r
31 Set\r
32 </term>\r
33 <listitem>\r
34 <simpara>\r
35         The path has the attribute with special value "true";\r
36         this is specified by listing only the name of the\r
37         attribute in the attribute list.\r
38 </simpara>\r
39 </listitem>\r
40 </varlistentry>\r
41 <varlistentry>\r
42 <term>\r
43 Unset\r
44 </term>\r
45 <listitem>\r
46 <simpara>\r
47         The path has the attribute with special value "false";\r
48         this is specified by listing the name of the attribute\r
49         prefixed with a dash <emphasis>-</emphasis> in the attribute list.\r
50 </simpara>\r
51 </listitem>\r
52 </varlistentry>\r
53 <varlistentry>\r
54 <term>\r
55 Set to a value\r
56 </term>\r
57 <listitem>\r
58 <simpara>\r
59         The path has the attribute with specified string value;\r
60         this is specified by listing the name of the attribute\r
61         followed by an equal sign <emphasis>=</emphasis> and its value in the\r
62         attribute list.\r
63 </simpara>\r
64 </listitem>\r
65 </varlistentry>\r
66 <varlistentry>\r
67 <term>\r
68 Unspecified\r
69 </term>\r
70 <listitem>\r
71 <simpara>\r
72         No pattern matches the path, and nothing says if\r
73         the path has or does not have the attribute, the\r
74         attribute for the path is said to be Unspecified.\r
75 </simpara>\r
76 </listitem>\r
77 </varlistentry>\r
78 </variablelist>\r
79 <simpara>When more than one pattern matches the path, a later line\r
80 overrides an earlier line.  This overriding is done per\r
81 attribute.  The rules how the pattern matches paths are the\r
82 same as in <emphasis>.gitignore</emphasis> files; see <xref linkend="gitignore(5)" />.\r
83 Unlike <emphasis>.gitignore</emphasis>, negative patterns are forbidden.</simpara>\r
84 <simpara>When deciding what attributes are assigned to a path, git\r
85 consults <emphasis>$GIT_DIR/info/attributes</emphasis> file (which has the highest\r
86 precedence), <emphasis>.gitattributes</emphasis> file in the same directory as the\r
87 path in question, and its parent directories up to the toplevel of the\r
88 work tree (the further the directory that contains <emphasis>.gitattributes</emphasis>\r
89 is from the path in question, the lower its precedence). Finally\r
90 global and system-wide files are considered (they have the lowest\r
91 precedence).</simpara>\r
92 <simpara>When the <emphasis>.gitattributes</emphasis> file is missing from the work tree, the\r
93 path in the index is used as a fall-back.  During checkout process,\r
94 <emphasis>.gitattributes</emphasis> in the index is used and then the file in the\r
95 working tree is used as a fall-back.</simpara>\r
96 <simpara>If you wish to affect only a single repository (i.e., to assign\r
97 attributes to files that are particular to\r
98 one user's workflow for that repository), then\r
99 attributes should be placed in the <emphasis>$GIT_DIR/info/attributes</emphasis> file.\r
100 Attributes which should be version-controlled and distributed to other\r
101 repositories (i.e., attributes of interest to all users) should go into\r
102 <emphasis>.gitattributes</emphasis> files. Attributes that should affect all repositories\r
103 for a single user should be placed in a file specified by the\r
104 <emphasis>core.attributesfile</emphasis> configuration option (see <xref linkend="git-config(1)" />).\r
105 Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME\r
106 is either not set or empty, $HOME/.config/git/attributes is used instead.\r
107 Attributes for all users on a system should be placed in the\r
108 <emphasis>$(prefix)/etc/gitattributes</emphasis> file.</simpara>\r
109 <simpara>Sometimes you would need to override an setting of an attribute\r
110 for a path to <emphasis>Unspecified</emphasis> state.  This can be done by listing\r
111 the name of the attribute prefixed with an exclamation point <emphasis>!</emphasis>.</simpara>\r
112 </simplesect>\r
113 <simplesect id="gitattributes(5)__effects">\r
114 <title>EFFECTS</title>\r
115 <simpara>Certain operations by git can be influenced by assigning\r
116 particular attributes to a path.  Currently, the following\r
117 operations are attributes-aware.</simpara>\r
118 <section id="gitattributes(5)__checking_out_and_checking_in">\r
119 <title>Checking-out and checking-in</title>\r
120 <simpara>These attributes affect how the contents stored in the\r
121 repository are copied to the working tree files when commands\r
122 such as <emphasis>git checkout</emphasis> and <emphasis>git merge</emphasis> run.  They also affect how\r
123 git stores the contents you prepare in the working tree in the\r
124 repository upon <emphasis>git add</emphasis> and <emphasis>git commit</emphasis>.</simpara>\r
125 <section id="gitattributes(5)__emphasis_text_emphasis">\r
126 <title><emphasis>text</emphasis></title>\r
127 <simpara>This attribute enables and controls end-of-line normalization.  When a\r
128 text file is normalized, its line endings are converted to LF in the\r
129 repository.  To control what line ending style is used in the working\r
130 directory, use the <emphasis>eol</emphasis> attribute for a single file and the\r
131 <emphasis>core.eol</emphasis> configuration variable for all text files.</simpara>\r
132 <variablelist>\r
133 <varlistentry>\r
134 <term>\r
135 Set\r
136 </term>\r
137 <listitem>\r
138 <simpara>\r
139         Setting the <emphasis>text</emphasis> attribute on a path enables end-of-line\r
140         normalization and marks the path as a text file.  End-of-line\r
141         conversion takes place without guessing the content type.\r
142 </simpara>\r
143 </listitem>\r
144 </varlistentry>\r
145 <varlistentry>\r
146 <term>\r
147 Unset\r
148 </term>\r
149 <listitem>\r
150 <simpara>\r
151         Unsetting the <emphasis>text</emphasis> attribute on a path tells git not to\r
152         attempt any end-of-line conversion upon checkin or checkout.\r
153 </simpara>\r
154 </listitem>\r
155 </varlistentry>\r
156 <varlistentry>\r
157 <term>\r
158 Set to string value "auto"\r
159 </term>\r
160 <listitem>\r
161 <simpara>\r
162         When <emphasis>text</emphasis> is set to "auto", the path is marked for automatic\r
163         end-of-line normalization.  If git decides that the content is\r
164         text, its line endings are normalized to LF on checkin.\r
165 </simpara>\r
166 </listitem>\r
167 </varlistentry>\r
168 <varlistentry>\r
169 <term>\r
170 Unspecified\r
171 </term>\r
172 <listitem>\r
173 <simpara>\r
174         If the <emphasis>text</emphasis> attribute is unspecified, git uses the\r
175         <emphasis>core.autocrlf</emphasis> configuration variable to determine if the\r
176         file should be converted.\r
177 </simpara>\r
178 </listitem>\r
179 </varlistentry>\r
180 </variablelist>\r
181 <simpara>Any other value causes git to act as if <emphasis>text</emphasis> has been left\r
182 unspecified.</simpara>\r
183 </section>\r
184 <section id="gitattributes(5)__emphasis_eol_emphasis">\r
185 <title><emphasis>eol</emphasis></title>\r
186 <simpara>This attribute sets a specific line-ending style to be used in the\r
187 working directory.  It enables end-of-line normalization without any\r
188 content checks, effectively setting the <emphasis>text</emphasis> attribute.</simpara>\r
189 <variablelist>\r
190 <varlistentry>\r
191 <term>\r
192 Set to string value "crlf"\r
193 </term>\r
194 <listitem>\r
195 <simpara>\r
196         This setting forces git to normalize line endings for this\r
197         file on checkin and convert them to CRLF when the file is\r
198         checked out.\r
199 </simpara>\r
200 </listitem>\r
201 </varlistentry>\r
202 <varlistentry>\r
203 <term>\r
204 Set to string value "lf"\r
205 </term>\r
206 <listitem>\r
207 <simpara>\r
208         This setting forces git to normalize line endings to LF on\r
209         checkin and prevents conversion to CRLF when the file is\r
210         checked out.\r
211 </simpara>\r
212 </listitem>\r
213 </varlistentry>\r
214 </variablelist>\r
215 </section>\r
216 <section id="gitattributes(5)__backwards_compatibility_with_emphasis_crlf_emphasis_attribute">\r
217 <title>Backwards compatibility with <emphasis>crlf</emphasis> attribute</title>\r
218 <simpara>For backwards compatibility, the <emphasis>crlf</emphasis> attribute is interpreted as\r
219 follows:</simpara>\r
220 <screen>crlf            text\r
221 -crlf           -text\r
222 crlf=input      eol=lf</screen>\r
223 </section>\r
224 <section id="gitattributes(5)__end_of_line_conversion">\r
225 <title>End-of-line conversion</title>\r
226 <simpara>While git normally leaves file contents alone, it can be configured to\r
227 normalize line endings to LF in the repository and, optionally, to\r
228 convert them to CRLF when files are checked out.</simpara>\r
229 <simpara>Here is an example that will make git normalize .txt, .vcproj and .sh\r
230 files, ensure that .vcproj files have CRLF and .sh files have LF in\r
231 the working directory, and prevent .jpg files from being normalized\r
232 regardless of their content.</simpara>\r
233 <screen>*.txt           text\r
234 *.vcproj        eol=crlf\r
235 *.sh            eol=lf\r
236 *.jpg           -text</screen>\r
237 <simpara>Other source code management systems normalize all text files in their\r
238 repositories, and there are two ways to enable similar automatic\r
239 normalization in git.</simpara>\r
240 <simpara>If you simply want to have CRLF line endings in your working directory\r
241 regardless of the repository you are working with, you can set the\r
242 config variable "core.autocrlf" without changing any attributes.</simpara>\r
243 <screen>[core]\r
244         autocrlf = true</screen>\r
245 <simpara>This does not force normalization of all text files, but does ensure\r
246 that text files that you introduce to the repository have their line\r
247 endings normalized to LF when they are added, and that files that are\r
248 already normalized in the repository stay normalized.</simpara>\r
249 <simpara>If you want to interoperate with a source code management system that\r
250 enforces end-of-line normalization, or you simply want all text files\r
251 in your repository to be normalized, you should instead set the <emphasis>text</emphasis>\r
252 attribute to "auto" for <emphasis>all</emphasis> files.</simpara>\r
253 <screen>*       text=auto</screen>\r
254 <simpara>This ensures that all files that git considers to be text will have\r
255 normalized (LF) line endings in the repository.  The <emphasis>core.eol</emphasis>\r
256 configuration variable controls which line endings git will use for\r
257 normalized files in your working directory; the default is to use the\r
258 native line ending for your platform, or CRLF if <emphasis>core.autocrlf</emphasis> is\r
259 set.</simpara>\r
260 <note><simpara>When <emphasis>text=auto</emphasis> normalization is enabled in an existing\r
261 repository, any text files containing CRLFs should be normalized.  If\r
262 they are not they will be normalized the next time someone tries to\r
263 change them, causing unfortunate misattribution.  From a clean working\r
264 directory:</simpara></note>\r
265 <screen>$ echo "* text=auto" &gt;&gt;.gitattributes\r
266 $ rm .git/index     # Remove the index to force git to\r
267 $ git reset         # re-scan the working directory\r
268 $ git status        # Show files that will be normalized\r
269 $ git add -u\r
270 $ git add .gitattributes\r
271 $ git commit -m "Introduce end-of-line normalization"</screen>\r
272 <simpara>If any files that should not be normalized show up in <emphasis>git status</emphasis>,\r
273 unset their <emphasis>text</emphasis> attribute before running <emphasis>git add -u</emphasis>.</simpara>\r
274 <screen>manual.pdf      -text</screen>\r
275 <simpara>Conversely, text files that git does not detect can have normalization\r
276 enabled manually.</simpara>\r
277 <screen>weirdchars.txt  text</screen>\r
278 <simpara>If <emphasis>core.safecrlf</emphasis> is set to "true" or "warn", git verifies if\r
279 the conversion is reversible for the current setting of\r
280 <emphasis>core.autocrlf</emphasis>.  For "true", git rejects irreversible\r
281 conversions; for "warn", git only prints a warning but accepts\r
282 an irreversible conversion.  The safety triggers to prevent such\r
283 a conversion done to the files in the work tree, but there are a\r
284 few exceptions.  Even though&#8230;</simpara>\r
285 <itemizedlist>\r
286 <listitem>\r
287 <simpara>\r
288 <emphasis>git add</emphasis> itself does not touch the files in the work tree, the\r
289   next checkout would, so the safety triggers;\r
290 </simpara>\r
291 </listitem>\r
292 <listitem>\r
293 <simpara>\r
294 <emphasis>git apply</emphasis> to update a text file with a patch does touch the files\r
295   in the work tree, but the operation is about text files and CRLF\r
296   conversion is about fixing the line ending inconsistencies, so the\r
297   safety does not trigger;\r
298 </simpara>\r
299 </listitem>\r
300 <listitem>\r
301 <simpara>\r
302 <emphasis>git diff</emphasis> itself does not touch the files in the work tree, it is\r
303   often run to inspect the changes you intend to next <emphasis>git add</emphasis>.  To\r
304   catch potential problems early, safety triggers.\r
305 </simpara>\r
306 </listitem>\r
307 </itemizedlist>\r
308 </section>\r
309 <section id="gitattributes(5)__emphasis_ident_emphasis">\r
310 <title><emphasis>ident</emphasis></title>\r
311 <simpara>When the attribute <emphasis>ident</emphasis> is set for a path, git replaces\r
312 <emphasis>$Id$</emphasis> in the blob object with <emphasis>$Id:</emphasis>, followed by the\r
313 40-character hexadecimal blob object name, followed by a dollar\r
314 sign <emphasis>$</emphasis> upon checkout.  Any byte sequence that begins with\r
315 <emphasis>$Id:</emphasis> and ends with <emphasis>$</emphasis> in the worktree file is replaced\r
316 with <emphasis>$Id$</emphasis> upon check-in.</simpara>\r
317 </section>\r
318 <section id="gitattributes(5)__emphasis_filter_emphasis">\r
319 <title><emphasis>filter</emphasis></title>\r
320 <simpara>A <emphasis>filter</emphasis> attribute can be set to a string value that names a\r
321 filter driver specified in the configuration.</simpara>\r
322 <simpara>A filter driver consists of a <emphasis>clean</emphasis> command and a <emphasis>smudge</emphasis>\r
323 command, either of which can be left unspecified.  Upon\r
324 checkout, when the <emphasis>smudge</emphasis> command is specified, the command is\r
325 fed the blob object from its standard input, and its standard\r
326 output is used to update the worktree file.  Similarly, the\r
327 <emphasis>clean</emphasis> command is used to convert the contents of worktree file\r
328 upon checkin.</simpara>\r
329 <simpara>One use of the content filtering is to massage the content into a shape\r
330 that is more convenient for the platform, filesystem, and the user to use.\r
331 For this mode of operation, the key phrase here is "more convenient" and\r
332 not "turning something unusable into usable".  In other words, the intent\r
333 is that if someone unsets the filter driver definition, or does not have\r
334 the appropriate filter program, the project should still be usable.</simpara>\r
335 <simpara>Another use of the content filtering is to store the content that cannot\r
336 be directly used in the repository (e.g. a UUID that refers to the true\r
337 content stored outside git, or an encrypted content) and turn it into a\r
338 usable form upon checkout (e.g. download the external content, or decrypt\r
339 the encrypted content).</simpara>\r
340 <simpara>These two filters behave differently, and by default, a filter is taken as\r
341 the former, massaging the contents into more convenient shape.  A missing\r
342 filter driver definition in the config, or a filter driver that exits with\r
343 a non-zero status, is not an error but makes the filter a no-op passthru.</simpara>\r
344 <simpara>You can declare that a filter turns a content that by itself is unusable\r
345 into a usable content by setting the filter.&lt;driver&gt;.required configuration\r
346 variable to <emphasis>true</emphasis>.</simpara>\r
347 <simpara>For example, in .gitattributes, you would assign the <emphasis>filter</emphasis>\r
348 attribute for paths.</simpara>\r
349 <screen>*.c     filter=indent</screen>\r
350 <simpara>Then you would define a "filter.indent.clean" and "filter.indent.smudge"\r
351 configuration in your .git/config to specify a pair of commands to\r
352 modify the contents of C programs when the source files are checked\r
353 in ("clean" is run) and checked out (no change is made because the\r
354 command is "cat").</simpara>\r
355 <screen>[filter "indent"]\r
356         clean = indent\r
357         smudge = cat</screen>\r
358 <simpara>For best results, <emphasis>clean</emphasis> should not alter its output further if it is\r
359 run twice ("clean&#8594;clean" should be equivalent to "clean"), and\r
360 multiple <emphasis>smudge</emphasis> commands should not alter <emphasis>clean</emphasis>'s output\r
361 ("smudge&#8594;smudge&#8594;clean" should be equivalent to "clean").  See the\r
362 section on merging below.</simpara>\r
363 <simpara>The "indent" filter is well-behaved in this regard: it will not modify\r
364 input that is already correctly indented.  In this case, the lack of a\r
365 smudge filter means that the clean filter <emphasis>must</emphasis> accept its own output\r
366 without modifying it.</simpara>\r
367 <simpara>If a filter <emphasis>must</emphasis> succeed in order to make the stored contents usable,\r
368 you can declare that the filter is <emphasis>required</emphasis>, in the configuration:</simpara>\r
369 <screen>[filter "crypt"]\r
370         clean = openssl enc ...\r
371         smudge = openssl enc -d ...\r
372         required</screen>\r
373 <simpara>Sequence "%f" on the filter command line is replaced with the name of\r
374 the file the filter is working on.  A filter might use this in keyword\r
375 substitution.  For example:</simpara>\r
376 <screen>[filter "p4"]\r
377         clean = git-p4-filter --clean %f\r
378         smudge = git-p4-filter --smudge %f</screen>\r
379 </section>\r
380 <section id="gitattributes(5)__interaction_between_checkin_checkout_attributes">\r
381 <title>Interaction between checkin/checkout attributes</title>\r
382 <simpara>In the check-in codepath, the worktree file is first converted\r
383 with <emphasis>filter</emphasis> driver (if specified and corresponding driver\r
384 defined), then the result is processed with <emphasis>ident</emphasis> (if\r
385 specified), and then finally with <emphasis>text</emphasis> (again, if specified\r
386 and applicable).</simpara>\r
387 <simpara>In the check-out codepath, the blob content is first converted\r
388 with <emphasis>text</emphasis>, and then <emphasis>ident</emphasis> and fed to <emphasis>filter</emphasis>.</simpara>\r
389 </section>\r
390 <section id="gitattributes(5)__merging_branches_with_differing_checkin_checkout_attributes">\r
391 <title>Merging branches with differing checkin/checkout attributes</title>\r
392 <simpara>If you have added attributes to a file that cause the canonical\r
393 repository format for that file to change, such as adding a\r
394 clean/smudge filter or text/eol/ident attributes, merging anything\r
395 where the attribute is not in place would normally cause merge\r
396 conflicts.</simpara>\r
397 <simpara>To prevent these unnecessary merge conflicts, git can be told to run a\r
398 virtual check-out and check-in of all three stages of a file when\r
399 resolving a three-way merge by setting the <emphasis>merge.renormalize</emphasis>\r
400 configuration variable.  This prevents changes caused by check-in\r
401 conversion from causing spurious merge conflicts when a converted file\r
402 is merged with an unconverted file.</simpara>\r
403 <simpara>As long as a "smudge&#8594;clean" results in the same output as a "clean"\r
404 even on files that are already smudged, this strategy will\r
405 automatically resolve all filter-related conflicts.  Filters that do\r
406 not act in this way may cause additional merge conflicts that must be\r
407 resolved manually.</simpara>\r
408 </section>\r
409 </section>\r
410 <section id="gitattributes(5)__generating_diff_text">\r
411 <title>Generating diff text</title>\r
412 <section id="gitattributes(5)__emphasis_diff_emphasis">\r
413 <title><emphasis>diff</emphasis></title>\r
414 <simpara>The attribute <emphasis>diff</emphasis> affects how <emphasis>git</emphasis> generates diffs for particular\r
415 files. It can tell git whether to generate a textual patch for the path\r
416 or to treat the path as a binary file.  It can also affect what line is\r
417 shown on the hunk header <emphasis>@@ -k,l +n,m @@</emphasis> line, tell git to use an\r
418 external command to generate the diff, or ask git to convert binary\r
419 files to a text format before generating the diff.</simpara>\r
420 <variablelist>\r
421 <varlistentry>\r
422 <term>\r
423 Set\r
424 </term>\r
425 <listitem>\r
426 <simpara>\r
427         A path to which the <emphasis>diff</emphasis> attribute is set is treated\r
428         as text, even when they contain byte values that\r
429         normally never appear in text files, such as NUL.\r
430 </simpara>\r
431 </listitem>\r
432 </varlistentry>\r
433 <varlistentry>\r
434 <term>\r
435 Unset\r
436 </term>\r
437 <listitem>\r
438 <simpara>\r
439         A path to which the <emphasis>diff</emphasis> attribute is unset will\r
440         generate <emphasis>Binary files differ</emphasis> (or a binary patch, if\r
441         binary patches are enabled).\r
442 </simpara>\r
443 </listitem>\r
444 </varlistentry>\r
445 <varlistentry>\r
446 <term>\r
447 Unspecified\r
448 </term>\r
449 <listitem>\r
450 <simpara>\r
451         A path to which the <emphasis>diff</emphasis> attribute is unspecified\r
452         first gets its contents inspected, and if it looks like\r
453         text, it is treated as text.  Otherwise it would\r
454         generate <emphasis>Binary files differ</emphasis>.\r
455 </simpara>\r
456 </listitem>\r
457 </varlistentry>\r
458 <varlistentry>\r
459 <term>\r
460 String\r
461 </term>\r
462 <listitem>\r
463 <simpara>\r
464         Diff is shown using the specified diff driver.  Each driver may\r
465         specify one or more options, as described in the following\r
466         section. The options for the diff driver "foo" are defined\r
467         by the configuration variables in the "diff.foo" section of the\r
468         git config file.\r
469 </simpara>\r
470 </listitem>\r
471 </varlistentry>\r
472 </variablelist>\r
473 </section>\r
474 <section id="gitattributes(5)__defining_an_external_diff_driver">\r
475 <title>Defining an external diff driver</title>\r
476 <simpara>The definition of a diff driver is done in <emphasis>gitconfig</emphasis>, not\r
477 <emphasis>gitattributes</emphasis> file, so strictly speaking this manual page is a\r
478 wrong place to talk about it.  However&#8230;</simpara>\r
479 <simpara>To define an external diff driver <emphasis>jcdiff</emphasis>, add a section to your\r
480 <emphasis>$GIT_DIR/config</emphasis> file (or <emphasis>$HOME/.gitconfig</emphasis> file) like this:</simpara>\r
481 <screen>[diff "jcdiff"]\r
482         command = j-c-diff</screen>\r
483 <simpara>When git needs to show you a diff for the path with <emphasis>diff</emphasis>\r
484 attribute set to <emphasis>jcdiff</emphasis>, it calls the command you specified\r
485 with the above configuration, i.e. <emphasis>j-c-diff</emphasis>, with 7\r
486 parameters, just like <emphasis>GIT_EXTERNAL_DIFF</emphasis> program is called.\r
487 See <xref linkend="git(1)" /> for details.</simpara>\r
488 </section>\r
489 <section id="gitattributes(5)__defining_a_custom_hunk_header">\r
490 <title>Defining a custom hunk-header</title>\r
491 <simpara>Each group of changes (called a "hunk") in the textual diff output\r
492 is prefixed with a line of the form:</simpara>\r
493 <literallayout class="monospaced">@@ -k,l +n,m @@ TEXT</literallayout>\r
494 <simpara>This is called a <emphasis>hunk header</emphasis>.  The "TEXT" portion is by default a line\r
495 that begins with an alphabet, an underscore or a dollar sign; this\r
496 matches what GNU <emphasis>diff -p</emphasis> output uses.  This default selection however\r
497 is not suited for some contents, and you can use a customized pattern\r
498 to make a selection.</simpara>\r
499 <simpara>First, in .gitattributes, you would assign the <emphasis>diff</emphasis> attribute\r
500 for paths.</simpara>\r
501 <screen>*.tex   diff=tex</screen>\r
502 <simpara>Then, you would define a "diff.tex.xfuncname" configuration to\r
503 specify a regular expression that matches a line that you would\r
504 want to appear as the hunk header "TEXT". Add a section to your\r
505 <emphasis>$GIT_DIR/config</emphasis> file (or <emphasis>$HOME/.gitconfig</emphasis> file) like this:</simpara>\r
506 <screen>[diff "tex"]\r
507         xfuncname = "^(\\\\(sub)*section\\{.*)$"</screen>\r
508 <simpara>Note.  A single level of backslashes are eaten by the\r
509 configuration file parser, so you would need to double the\r
510 backslashes; the pattern above picks a line that begins with a\r
511 backslash, and zero or more occurrences of <emphasis>sub</emphasis> followed by\r
512 <emphasis>section</emphasis> followed by open brace, to the end of line.</simpara>\r
513 <simpara>There are a few built-in patterns to make this easier, and <emphasis>tex</emphasis>\r
514 is one of them, so you do not have to write the above in your\r
515 configuration file (you still need to enable this with the\r
516 attribute mechanism, via <emphasis>.gitattributes</emphasis>).  The following built in\r
517 patterns are available:</simpara>\r
518 <itemizedlist>\r
519 <listitem>\r
520 <simpara>\r
521 <emphasis>ada</emphasis> suitable for source code in the Ada language.\r
522 </simpara>\r
523 </listitem>\r
524 <listitem>\r
525 <simpara>\r
526 <emphasis>bibtex</emphasis> suitable for files with BibTeX coded references.\r
527 </simpara>\r
528 </listitem>\r
529 <listitem>\r
530 <simpara>\r
531 <emphasis>cpp</emphasis> suitable for source code in the C and C++ languages.\r
532 </simpara>\r
533 </listitem>\r
534 <listitem>\r
535 <simpara>\r
536 <emphasis>csharp</emphasis> suitable for source code in the C# language.\r
537 </simpara>\r
538 </listitem>\r
539 <listitem>\r
540 <simpara>\r
541 <emphasis>fortran</emphasis> suitable for source code in the Fortran language.\r
542 </simpara>\r
543 </listitem>\r
544 <listitem>\r
545 <simpara>\r
546 <emphasis>html</emphasis> suitable for HTML/XHTML documents.\r
547 </simpara>\r
548 </listitem>\r
549 <listitem>\r
550 <simpara>\r
551 <emphasis>java</emphasis> suitable for source code in the Java language.\r
552 </simpara>\r
553 </listitem>\r
554 <listitem>\r
555 <simpara>\r
556 <emphasis>matlab</emphasis> suitable for source code in the MATLAB language.\r
557 </simpara>\r
558 </listitem>\r
559 <listitem>\r
560 <simpara>\r
561 <emphasis>objc</emphasis> suitable for source code in the Objective-C language.\r
562 </simpara>\r
563 </listitem>\r
564 <listitem>\r
565 <simpara>\r
566 <emphasis>pascal</emphasis> suitable for source code in the Pascal/Delphi language.\r
567 </simpara>\r
568 </listitem>\r
569 <listitem>\r
570 <simpara>\r
571 <emphasis>perl</emphasis> suitable for source code in the Perl language.\r
572 </simpara>\r
573 </listitem>\r
574 <listitem>\r
575 <simpara>\r
576 <emphasis>php</emphasis> suitable for source code in the PHP language.\r
577 </simpara>\r
578 </listitem>\r
579 <listitem>\r
580 <simpara>\r
581 <emphasis>python</emphasis> suitable for source code in the Python language.\r
582 </simpara>\r
583 </listitem>\r
584 <listitem>\r
585 <simpara>\r
586 <emphasis>ruby</emphasis> suitable for source code in the Ruby language.\r
587 </simpara>\r
588 </listitem>\r
589 <listitem>\r
590 <simpara>\r
591 <emphasis>tex</emphasis> suitable for source code for LaTeX documents.\r
592 </simpara>\r
593 </listitem>\r
594 </itemizedlist>\r
595 </section>\r
596 <section id="gitattributes(5)__customizing_word_diff">\r
597 <title>Customizing word diff</title>\r
598 <simpara>You can customize the rules that <emphasis>git diff --word-diff</emphasis> uses to\r
599 split words in a line, by specifying an appropriate regular expression\r
600 in the "diff.*.wordRegex" configuration variable.  For example, in TeX\r
601 a backslash followed by a sequence of letters forms a command, but\r
602 several such commands can be run together without intervening\r
603 whitespace.  To separate them, use a regular expression in your\r
604 <emphasis>$GIT_DIR/config</emphasis> file (or <emphasis>$HOME/.gitconfig</emphasis> file) like this:</simpara>\r
605 <screen>[diff "tex"]\r
606         wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"</screen>\r
607 <simpara>A built-in pattern is provided for all languages listed in the\r
608 previous section.</simpara>\r
609 </section>\r
610 <section id="gitattributes(5)__performing_text_diffs_of_binary_files">\r
611 <title>Performing text diffs of binary files</title>\r
612 <simpara>Sometimes it is desirable to see the diff of a text-converted\r
613 version of some binary files. For example, a word processor\r
614 document can be converted to an ASCII text representation, and\r
615 the diff of the text shown. Even though this conversion loses\r
616 some information, the resulting diff is useful for human\r
617 viewing (but cannot be applied directly).</simpara>\r
618 <simpara>The <emphasis>textconv</emphasis> config option is used to define a program for\r
619 performing such a conversion. The program should take a single\r
620 argument, the name of a file to convert, and produce the\r
621 resulting text on stdout.</simpara>\r
622 <simpara>For example, to show the diff of the exif information of a\r
623 file instead of the binary information (assuming you have the\r
624 exif tool installed), add the following section to your\r
625 <emphasis>$GIT_DIR/config</emphasis> file (or <emphasis>$HOME/.gitconfig</emphasis> file):</simpara>\r
626 <screen>[diff "jpg"]\r
627         textconv = exif</screen>\r
628 <note><simpara>The text conversion is generally a one-way conversion;\r
629 in this example, we lose the actual image contents and focus\r
630 just on the text data. This means that diffs generated by\r
631 textconv are <emphasis>not</emphasis> suitable for applying. For this reason,\r
632 only <emphasis>git diff</emphasis> and the <emphasis>git log</emphasis> family of commands (i.e.,\r
633 log, whatchanged, show) will perform text conversion. <emphasis>git\r
634 format-patch</emphasis> will never generate this output. If you want to\r
635 send somebody a text-converted diff of a binary file (e.g.,\r
636 because it quickly conveys the changes you have made), you\r
637 should generate it separately and send it as a comment <emphasis>in\r
638 addition to</emphasis> the usual binary diff that you might send.</simpara></note>\r
639 <simpara>Because text conversion can be slow, especially when doing a\r
640 large number of them with <emphasis>git log -p</emphasis>, git provides a mechanism\r
641 to cache the output and use it in future diffs.  To enable\r
642 caching, set the "cachetextconv" variable in your diff driver's\r
643 config. For example:</simpara>\r
644 <screen>[diff "jpg"]\r
645         textconv = exif\r
646         cachetextconv = true</screen>\r
647 <simpara>This will cache the result of running "exif" on each blob\r
648 indefinitely. If you change the textconv config variable for a\r
649 diff driver, git will automatically invalidate the cache entries\r
650 and re-run the textconv filter. If you want to invalidate the\r
651 cache manually (e.g., because your version of "exif" was updated\r
652 and now produces better output), you can remove the cache\r
653 manually with <emphasis>git update-ref -d refs/notes/textconv/jpg</emphasis> (where\r
654 "jpg" is the name of the diff driver, as in the example above).</simpara>\r
655 </section>\r
656 <section id="gitattributes(5)__choosing_textconv_versus_external_diff">\r
657 <title>Choosing textconv versus external diff</title>\r
658 <simpara>If you want to show differences between binary or specially-formatted\r
659 blobs in your repository, you can choose to use either an external diff\r
660 command, or to use textconv to convert them to a diff-able text format.\r
661 Which method you choose depends on your exact situation.</simpara>\r
662 <simpara>The advantage of using an external diff command is flexibility. You are\r
663 not bound to find line-oriented changes, nor is it necessary for the\r
664 output to resemble unified diff. You are free to locate and report\r
665 changes in the most appropriate way for your data format.</simpara>\r
666 <simpara>A textconv, by comparison, is much more limiting. You provide a\r
667 transformation of the data into a line-oriented text format, and git\r
668 uses its regular diff tools to generate the output. There are several\r
669 advantages to choosing this method:</simpara>\r
670 <orderedlist numeration="arabic">\r
671 <listitem>\r
672 <simpara>\r
673 Ease of use. It is often much simpler to write a binary to text\r
674    transformation than it is to perform your own diff. In many cases,\r
675    existing programs can be used as textconv filters (e.g., exif,\r
676    odt2txt).\r
677 </simpara>\r
678 </listitem>\r
679 <listitem>\r
680 <simpara>\r
681 Git diff features. By performing only the transformation step\r
682    yourself, you can still utilize many of git's diff features,\r
683    including colorization, word-diff, and combined diffs for merges.\r
684 </simpara>\r
685 </listitem>\r
686 <listitem>\r
687 <simpara>\r
688 Caching. Textconv caching can speed up repeated diffs, such as those\r
689    you might trigger by running <emphasis>git log -p</emphasis>.\r
690 </simpara>\r
691 </listitem>\r
692 </orderedlist>\r
693 </section>\r
694 <section id="gitattributes(5)__marking_files_as_binary">\r
695 <title>Marking files as binary</title>\r
696 <simpara>Git usually guesses correctly whether a blob contains text or binary\r
697 data by examining the beginning of the contents. However, sometimes you\r
698 may want to override its decision, either because a blob contains binary\r
699 data later in the file, or because the content, while technically\r
700 composed of text characters, is opaque to a human reader. For example,\r
701 many postscript files contain only ascii characters, but produce noisy\r
702 and meaningless diffs.</simpara>\r
703 <simpara>The simplest way to mark a file as binary is to unset the diff\r
704 attribute in the <emphasis>.gitattributes</emphasis> file:</simpara>\r
705 <screen>*.ps -diff</screen>\r
706 <simpara>This will cause git to generate <emphasis>Binary files differ</emphasis> (or a binary\r
707 patch, if binary patches are enabled) instead of a regular diff.</simpara>\r
708 <simpara>However, one may also want to specify other diff driver attributes. For\r
709 example, you might want to use <emphasis>textconv</emphasis> to convert postscript files to\r
710 an ascii representation for human viewing, but otherwise treat them as\r
711 binary files. You cannot specify both <emphasis>-diff</emphasis> and <emphasis>diff=ps</emphasis> attributes.\r
712 The solution is to use the <emphasis>diff.*.binary</emphasis> config option:</simpara>\r
713 <screen>[diff "ps"]\r
714   textconv = ps2ascii\r
715   binary = true</screen>\r
716 </section>\r
717 </section>\r
718 <section id="gitattributes(5)__performing_a_three_way_merge">\r
719 <title>Performing a three-way merge</title>\r
720 <section id="gitattributes(5)__emphasis_merge_emphasis">\r
721 <title><emphasis>merge</emphasis></title>\r
722 <simpara>The attribute <emphasis>merge</emphasis> affects how three versions of a file are\r
723 merged when a file-level merge is necessary during <emphasis>git merge</emphasis>,\r
724 and other commands such as <emphasis>git revert</emphasis> and <emphasis>git cherry-pick</emphasis>.</simpara>\r
725 <variablelist>\r
726 <varlistentry>\r
727 <term>\r
728 Set\r
729 </term>\r
730 <listitem>\r
731 <simpara>\r
732         Built-in 3-way merge driver is used to merge the\r
733         contents in a way similar to <emphasis>merge</emphasis> command of <emphasis>RCS</emphasis>\r
734         suite.  This is suitable for ordinary text files.\r
735 </simpara>\r
736 </listitem>\r
737 </varlistentry>\r
738 <varlistentry>\r
739 <term>\r
740 Unset\r
741 </term>\r
742 <listitem>\r
743 <simpara>\r
744         Take the version from the current branch as the\r
745         tentative merge result, and declare that the merge has\r
746         conflicts.  This is suitable for binary files that do\r
747         not have a well-defined merge semantics.\r
748 </simpara>\r
749 </listitem>\r
750 </varlistentry>\r
751 <varlistentry>\r
752 <term>\r
753 Unspecified\r
754 </term>\r
755 <listitem>\r
756 <simpara>\r
757         By default, this uses the same built-in 3-way merge\r
758         driver as is the case when the <emphasis>merge</emphasis> attribute is set.\r
759         However, the <emphasis>merge.default</emphasis> configuration variable can name\r
760         different merge driver to be used with paths for which the\r
761         <emphasis>merge</emphasis> attribute is unspecified.\r
762 </simpara>\r
763 </listitem>\r
764 </varlistentry>\r
765 <varlistentry>\r
766 <term>\r
767 String\r
768 </term>\r
769 <listitem>\r
770 <simpara>\r
771         3-way merge is performed using the specified custom\r
772         merge driver.  The built-in 3-way merge driver can be\r
773         explicitly specified by asking for "text" driver; the\r
774         built-in "take the current branch" driver can be\r
775         requested with "binary".\r
776 </simpara>\r
777 </listitem>\r
778 </varlistentry>\r
779 </variablelist>\r
780 </section>\r
781 <section id="gitattributes(5)__built_in_merge_drivers">\r
782 <title>Built-in merge drivers</title>\r
783 <simpara>There are a few built-in low-level merge drivers defined that\r
784 can be asked for via the <emphasis>merge</emphasis> attribute.</simpara>\r
785 <variablelist>\r
786 <varlistentry>\r
787 <term>\r
788 text\r
789 </term>\r
790 <listitem>\r
791 <simpara>\r
792         Usual 3-way file level merge for text files.  Conflicted\r
793         regions are marked with conflict markers <emphasis>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</emphasis>,\r
794         <emphasis>=======</emphasis> and <emphasis>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</emphasis>.  The version from your branch\r
795         appears before the <emphasis>=======</emphasis> marker, and the version\r
796         from the merged branch appears after the <emphasis>=======</emphasis>\r
797         marker.\r
798 </simpara>\r
799 </listitem>\r
800 </varlistentry>\r
801 <varlistentry>\r
802 <term>\r
803 binary\r
804 </term>\r
805 <listitem>\r
806 <simpara>\r
807         Keep the version from your branch in the work tree, but\r
808         leave the path in the conflicted state for the user to\r
809         sort out.\r
810 </simpara>\r
811 </listitem>\r
812 </varlistentry>\r
813 <varlistentry>\r
814 <term>\r
815 union\r
816 </term>\r
817 <listitem>\r
818 <simpara>\r
819         Run 3-way file level merge for text files, but take\r
820         lines from both versions, instead of leaving conflict\r
821         markers.  This tends to leave the added lines in the\r
822         resulting file in random order and the user should\r
823         verify the result. Do not use this if you do not\r
824         understand the implications.\r
825 </simpara>\r
826 </listitem>\r
827 </varlistentry>\r
828 </variablelist>\r
829 </section>\r
830 <section id="gitattributes(5)__defining_a_custom_merge_driver">\r
831 <title>Defining a custom merge driver</title>\r
832 <simpara>The definition of a merge driver is done in the <emphasis>.git/config</emphasis>\r
833 file, not in the <emphasis>gitattributes</emphasis> file, so strictly speaking this\r
834 manual page is a wrong place to talk about it.  However&#8230;</simpara>\r
835 <simpara>To define a custom merge driver <emphasis>filfre</emphasis>, add a section to your\r
836 <emphasis>$GIT_DIR/config</emphasis> file (or <emphasis>$HOME/.gitconfig</emphasis> file) like this:</simpara>\r
837 <screen>[merge "filfre"]\r
838         name = feel-free merge driver\r
839         driver = filfre %O %A %B\r
840         recursive = binary</screen>\r
841 <simpara>The <emphasis>merge.*.name</emphasis> variable gives the driver a human-readable\r
842 name.</simpara>\r
843 <simpara>The merge.*.driver` variable's value is used to construct a\r
844 command to run to merge ancestor's version (<emphasis>%O</emphasis>), current\r
845 version (<emphasis>%A</emphasis>) and the other branches version (<emphasis>%B</emphasis>).  These\r
846 three tokens are replaced with the names of temporary files that\r
847 hold the contents of these versions when the command line is\r
848 built. Additionally, %L will be replaced with the conflict marker\r
849 size (see below).</simpara>\r
850 <simpara>The merge driver is expected to leave the result of the merge in\r
851 the file named with <emphasis>%A</emphasis> by overwriting it, and exit with zero\r
852 status if it managed to merge them cleanly, or non-zero if there\r
853 were conflicts.</simpara>\r
854 <simpara>The <emphasis>merge.*.recursive</emphasis> variable specifies what other merge\r
855 driver to use when the merge driver is called for an internal\r
856 merge between common ancestors, when there are more than one.\r
857 When left unspecified, the driver itself is used for both\r
858 internal merge and the final merge.</simpara>\r
859 </section>\r
860 <section id="gitattributes(5)__emphasis_conflict_marker_size_emphasis">\r
861 <title><emphasis>conflict-marker-size</emphasis></title>\r
862 <simpara>This attribute controls the length of conflict markers left in\r
863 the work tree file during a conflicted merge.  Only setting to\r
864 the value to a positive integer has any meaningful effect.</simpara>\r
865 <simpara>For example, this line in <emphasis>.gitattributes</emphasis> can be used to tell the merge\r
866 machinery to leave much longer (instead of the usual 7-character-long)\r
867 conflict markers when merging the file <emphasis>Documentation/git-merge.txt</emphasis>\r
868 results in a conflict.</simpara>\r
869 <screen>Documentation/git-merge.txt     conflict-marker-size=32</screen>\r
870 </section>\r
871 </section>\r
872 <section id="gitattributes(5)__checking_whitespace_errors">\r
873 <title>Checking whitespace errors</title>\r
874 <section id="gitattributes(5)__emphasis_whitespace_emphasis">\r
875 <title><emphasis>whitespace</emphasis></title>\r
876 <simpara>The <emphasis>core.whitespace</emphasis> configuration variable allows you to define what\r
877 <emphasis>diff</emphasis> and <emphasis>apply</emphasis> should consider whitespace errors for all paths in\r
878 the project (See <xref linkend="git-config(1)" />).  This attribute gives you finer\r
879 control per path.</simpara>\r
880 <variablelist>\r
881 <varlistentry>\r
882 <term>\r
883 Set\r
884 </term>\r
885 <listitem>\r
886 <simpara>\r
887         Notice all types of potential whitespace errors known to git.\r
888         The tab width is taken from the value of the <emphasis>core.whitespace</emphasis>\r
889         configuration variable.\r
890 </simpara>\r
891 </listitem>\r
892 </varlistentry>\r
893 <varlistentry>\r
894 <term>\r
895 Unset\r
896 </term>\r
897 <listitem>\r
898 <simpara>\r
899         Do not notice anything as error.\r
900 </simpara>\r
901 </listitem>\r
902 </varlistentry>\r
903 <varlistentry>\r
904 <term>\r
905 Unspecified\r
906 </term>\r
907 <listitem>\r
908 <simpara>\r
909         Use the value of the <emphasis>core.whitespace</emphasis> configuration variable to\r
910         decide what to notice as error.\r
911 </simpara>\r
912 </listitem>\r
913 </varlistentry>\r
914 <varlistentry>\r
915 <term>\r
916 String\r
917 </term>\r
918 <listitem>\r
919 <simpara>\r
920         Specify a comma separate list of common whitespace problems to\r
921         notice in the same format as the <emphasis>core.whitespace</emphasis> configuration\r
922         variable.\r
923 </simpara>\r
924 </listitem>\r
925 </varlistentry>\r
926 </variablelist>\r
927 </section>\r
928 </section>\r
929 <section id="gitattributes(5)__creating_an_archive">\r
930 <title>Creating an archive</title>\r
931 <section id="gitattributes(5)__emphasis_export_ignore_emphasis">\r
932 <title><emphasis>export-ignore</emphasis></title>\r
933 <simpara>Files and directories with the attribute <emphasis>export-ignore</emphasis> won't be added to\r
934 archive files.</simpara>\r
935 </section>\r
936 <section id="gitattributes(5)__emphasis_export_subst_emphasis">\r
937 <title><emphasis>export-subst</emphasis></title>\r
938 <simpara>If the attribute <emphasis>export-subst</emphasis> is set for a file then git will expand\r
939 several placeholders when adding this file to an archive.  The\r
940 expansion depends on the availability of a commit ID, i.e., if\r
941 <xref linkend="git-archive(1)" /> has been given a tree instead of a commit or a\r
942 tag then no replacement will be done.  The placeholders are the same\r
943 as those for the option <emphasis>--pretty=format:</emphasis> of <xref linkend="git-log(1)" />,\r
944 except that they need to be wrapped like this: <emphasis>$Format:PLACEHOLDERS$</emphasis>\r
945 in the file.  E.g. the string <emphasis>$Format:%H$</emphasis> will be replaced by the\r
946 commit hash.</simpara>\r
947 </section>\r
948 </section>\r
949 <section id="gitattributes(5)__packing_objects">\r
950 <title>Packing objects</title>\r
951 <section id="gitattributes(5)__emphasis_delta_emphasis">\r
952 <title><emphasis>delta</emphasis></title>\r
953 <simpara>Delta compression will not be attempted for blobs for paths with the\r
954 attribute <emphasis>delta</emphasis> set to false.</simpara>\r
955 </section>\r
956 </section>\r
957 <section id="gitattributes(5)__viewing_files_in_gui_tools">\r
958 <title>Viewing files in GUI tools</title>\r
959 <section id="gitattributes(5)__emphasis_encoding_emphasis">\r
960 <title><emphasis>encoding</emphasis></title>\r
961 <simpara>The value of this attribute specifies the character encoding that should\r
962 be used by GUI tools (e.g. <xref linkend="gitk(1)" /> and <xref linkend="git-gui(1)" />) to\r
963 display the contents of the relevant file. Note that due to performance\r
964 considerations <xref linkend="gitk(1)" /> does not use this attribute unless you\r
965 manually enable per-file encodings in its options.</simpara>\r
966 <simpara>If this attribute is not set or has an invalid value, the value of the\r
967 <emphasis>gui.encoding</emphasis> configuration variable is used instead\r
968 (See <xref linkend="git-config(1)" />).</simpara>\r
969 </section>\r
970 </section>\r
971 </simplesect>\r
972 <simplesect id="gitattributes(5)__using_macro_attributes">\r
973 <title>USING MACRO ATTRIBUTES</title>\r
974 <simpara>You do not want any end-of-line conversions applied to, nor textual diffs\r
975 produced for, any binary file you track.  You would need to specify e.g.</simpara>\r
976 <screen>*.jpg -text -diff</screen>\r
977 <simpara>but that may become cumbersome, when you have many attributes.  Using\r
978 macro attributes, you can define an attribute that, when set, also\r
979 sets or unsets a number of other attributes at the same time.  The\r
980 system knows a built-in macro attribute, <emphasis>binary</emphasis>:</simpara>\r
981 <screen>*.jpg binary</screen>\r
982 <simpara>Setting the "binary" attribute also unsets the "text" and "diff"\r
983 attributes as above.  Note that macro attributes can only be "Set",\r
984 though setting one might have the effect of setting or unsetting other\r
985 attributes or even returning other attributes to the "Unspecified"\r
986 state.</simpara>\r
987 </simplesect>\r
988 <simplesect id="gitattributes(5)__defining_macro_attributes">\r
989 <title>DEFINING MACRO ATTRIBUTES</title>\r
990 <simpara>Custom macro attributes can be defined only in the <emphasis>.gitattributes</emphasis>\r
991 file at the toplevel (i.e. not in any subdirectory).  The built-in\r
992 macro attribute "binary" is equivalent to:</simpara>\r
993 <screen>[attr]binary -diff -merge -text</screen>\r
994 </simplesect>\r
995 <simplesect id="gitattributes(5)__example">\r
996 <title>EXAMPLE</title>\r
997 <simpara>If you have these three <emphasis>gitattributes</emphasis> file:</simpara>\r
998 <screen>(in $GIT_DIR/info/attributes)\r
1000 a*      foo !bar -baz\r
1002 (in .gitattributes)\r
1003 abc     foo bar baz\r
1005 (in t/.gitattributes)\r
1006 ab*     merge=filfre\r
1007 abc     -foo -bar\r
1008 *.c     frotz</screen>\r
1009 <simpara>the attributes given to path <emphasis>t/abc</emphasis> are computed as follows:</simpara>\r
1010 <orderedlist numeration="arabic">\r
1011 <listitem>\r
1012 <simpara>\r
1013 By examining <emphasis>t/.gitattributes</emphasis> (which is in the same\r
1014    directory as the path in question), git finds that the first\r
1015    line matches.  <emphasis>merge</emphasis> attribute is set.  It also finds that\r
1016    the second line matches, and attributes <emphasis>foo</emphasis> and <emphasis>bar</emphasis>\r
1017    are unset.\r
1018 </simpara>\r
1019 </listitem>\r
1020 <listitem>\r
1021 <simpara>\r
1022 Then it examines <emphasis>.gitattributes</emphasis> (which is in the parent\r
1023    directory), and finds that the first line matches, but\r
1024    <emphasis>t/.gitattributes</emphasis> file already decided how <emphasis>merge</emphasis>, <emphasis>foo</emphasis>\r
1025    and <emphasis>bar</emphasis> attributes should be given to this path, so it\r
1026    leaves <emphasis>foo</emphasis> and <emphasis>bar</emphasis> unset.  Attribute <emphasis>baz</emphasis> is set.\r
1027 </simpara>\r
1028 </listitem>\r
1029 <listitem>\r
1030 <simpara>\r
1031 Finally it examines <emphasis>$GIT_DIR/info/attributes</emphasis>.  This file\r
1032    is used to override the in-tree settings.  The first line is\r
1033    a match, and <emphasis>foo</emphasis> is set, <emphasis>bar</emphasis> is reverted to unspecified\r
1034    state, and <emphasis>baz</emphasis> is unset.\r
1035 </simpara>\r
1036 </listitem>\r
1037 </orderedlist>\r
1038 <simpara>As the result, the attributes assignment to <emphasis>t/abc</emphasis> becomes:</simpara>\r
1039 <screen>foo     set to true\r
1040 bar     unspecified\r
1041 baz     set to false\r
1042 merge   set to string value "filfre"\r
1043 frotz   unspecified</screen>\r
1044 </simplesect>\r
1045 <simplesect id="gitattributes(5)__see_also">\r
1046 <title>SEE ALSO</title>\r
1047 <simpara><xref linkend="git-check-attr(1)" />.</simpara>\r
1048 </simplesect>\r
1049 <simplesect id="gitattributes(5)__git">\r
1050 <title>GIT</title>\r
1051 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
1052 </simplesect>\r
1053 </sect2>\r