Autogenerated HTML docs for v1.7.1-78-g212f0
[git/jnareb-git.git] / gitattributes.html
blobed1ff5278f6f58253942e5390927a8324786220d
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <meta name="generator" content="AsciiDoc 8.2.5" />
7 <style type="text/css">
8 /* Debug borders */
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11 border: 1px solid red;
15 body {
16 margin: 1em 5% 1em 5%;
19 a {
20 color: blue;
21 text-decoration: underline;
23 a:visited {
24 color: fuchsia;
27 em {
28 font-style: italic;
31 strong {
32 font-weight: bold;
35 tt {
36 color: navy;
39 h1, h2, h3, h4, h5, h6 {
40 color: #527bbd;
41 font-family: sans-serif;
42 margin-top: 1.2em;
43 margin-bottom: 0.5em;
44 line-height: 1.3;
47 h1, h2, h3 {
48 border-bottom: 2px solid silver;
50 h2 {
51 padding-top: 0.5em;
53 h3 {
54 float: left;
56 h3 + * {
57 clear: left;
60 div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
65 hr {
66 border: 1px solid silver;
69 p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
74 pre {
75 padding: 0;
76 margin: 0;
79 span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
83 font-size: 1.1em;
85 span#email {
87 span#revision {
88 font-family: sans-serif;
91 div#footer {
92 font-family: sans-serif;
93 font-size: small;
94 border-top: 2px solid silver;
95 padding-top: 0.5em;
96 margin-top: 4.0em;
98 div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
102 div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
107 div#preamble,
108 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110 div.admonitionblock {
111 margin-right: 10%;
112 margin-top: 1.5em;
113 margin-bottom: 1.5em;
115 div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
120 div.content { /* Block element content. */
121 padding: 0;
124 /* Block element titles. */
125 div.title, caption.title {
126 font-family: sans-serif;
127 font-weight: bold;
128 text-align: left;
129 margin-top: 1.0em;
130 margin-bottom: 0.5em;
132 div.title + * {
133 margin-top: 0;
136 td div.title:first-child {
137 margin-top: 0.0em;
139 div.content div.title:first-child {
140 margin-top: 0.0em;
142 div.content + div.title {
143 margin-top: 0.0em;
146 div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
152 div.listingblock {
153 margin-right: 0%;
155 div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
161 div.quoteblock > div.content {
162 padding-left: 2.0em;
165 div.attribution {
166 text-align: right;
168 div.verseblock + div.attribution {
169 text-align: left;
172 div.admonitionblock .icon {
173 vertical-align: top;
174 font-size: 1.1em;
175 font-weight: bold;
176 text-decoration: underline;
177 color: #527bbd;
178 padding-right: 0.5em;
180 div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
185 div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
190 div.verseblock div.content {
191 white-space: pre;
194 div.imageblock div.content { padding-left: 0; }
195 div.imageblock img { border: 1px solid silver; }
196 span.image img { border-style: none; }
198 dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
202 dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
207 dd > *:first-child {
208 margin-top: 0;
211 ul, ol {
212 list-style-position: outside;
214 div.olist2 ol {
215 list-style-type: lower-alpha;
218 div.tableblock > table {
219 border: 3px solid #527bbd;
221 thead {
222 font-family: sans-serif;
223 font-weight: bold;
225 tfoot {
226 font-weight: bold;
229 div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
233 div.hlist td {
234 padding-bottom: 5px;
236 td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
241 td.hlist2 {
242 vertical-align: top;
245 @media print {
246 div#footer-badges { display: none; }
249 div#toctitle {
250 color: #527bbd;
251 font-family: sans-serif;
252 font-size: 1.1em;
253 font-weight: bold;
254 margin-top: 1.0em;
255 margin-bottom: 0.1em;
258 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
262 div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
266 div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
270 div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
274 include1::./stylesheets/xhtml11-manpage.css[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div.sidebar-content {
278 background: #ffffee;
279 border: 1px solid silver;
280 padding: 0.5em;
282 div.sidebar-title, div.image-title {
283 font-family: sans-serif;
284 font-weight: bold;
285 margin-top: 0.0em;
286 margin-bottom: 0.5em;
289 div.listingblock div.content {
290 border: 1px solid silver;
291 background: #f4f4f4;
292 padding: 0.5em;
295 div.quoteblock-content {
296 padding-left: 2.0em;
299 div.exampleblock-content {
300 border-left: 2px solid silver;
301 padding-left: 0.5em;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc a:visited { color: blue; }
306 </style>
307 <title>gitattributes(5)</title>
308 </head>
309 <body>
310 <div id="header">
311 <h1>
312 gitattributes(5) Manual Page
313 </h1>
314 <h2>NAME</h2>
315 <div class="sectionbody">
316 <p>gitattributes -
317 defining attributes per path
318 </p>
319 </div>
320 </div>
321 <h2>SYNOPSIS</h2>
322 <div class="sectionbody">
323 <div class="para"><p>$GIT_DIR/info/attributes, .gitattributes</p></div>
324 </div>
325 <h2 id="_description">DESCRIPTION</h2>
326 <div class="sectionbody">
327 <div class="para"><p>A <tt>gitattributes</tt> file is a simple text file that gives
328 <tt>attributes</tt> to pathnames.</p></div>
329 <div class="para"><p>Each line in <tt>gitattributes</tt> file is of form:</p></div>
330 <div class="literalblock">
331 <div class="content">
332 <pre><tt>pattern attr1 attr2 ...</tt></pre>
333 </div></div>
334 <div class="para"><p>That is, a pattern followed by an attributes list,
335 separated by whitespaces. When the pattern matches the
336 path in question, the attributes listed on the line are given to
337 the path.</p></div>
338 <div class="para"><p>Each attribute can be in one of these states for a given path:</p></div>
339 <div class="vlist"><dl>
340 <dt>
342 </dt>
343 <dd>
345 The path has the attribute with special value "true";
346 this is specified by listing only the name of the
347 attribute in the attribute list.
348 </p>
349 </dd>
350 <dt>
351 Unset
352 </dt>
353 <dd>
355 The path has the attribute with special value "false";
356 this is specified by listing the name of the attribute
357 prefixed with a dash <tt>-</tt> in the attribute list.
358 </p>
359 </dd>
360 <dt>
361 Set to a value
362 </dt>
363 <dd>
365 The path has the attribute with specified string value;
366 this is specified by listing the name of the attribute
367 followed by an equal sign <tt>=</tt> and its value in the
368 attribute list.
369 </p>
370 </dd>
371 <dt>
372 Unspecified
373 </dt>
374 <dd>
376 No pattern matches the path, and nothing says if
377 the path has or does not have the attribute, the
378 attribute for the path is said to be Unspecified.
379 </p>
380 </dd>
381 </dl></div>
382 <div class="para"><p>When more than one pattern matches the path, a later line
383 overrides an earlier line. This overriding is done per
384 attribute. The rules how the pattern matches paths are the
385 same as in <tt>.gitignore</tt> files; see <a href="gitignore.html">gitignore(5)</a>.</p></div>
386 <div class="para"><p>When deciding what attributes are assigned to a path, git
387 consults <tt>$GIT_DIR/info/attributes</tt> file (which has the highest
388 precedence), <tt>.gitattributes</tt> file in the same directory as the
389 path in question, and its parent directories up to the toplevel of the
390 work tree (the further the directory that contains <tt>.gitattributes</tt>
391 is from the path in question, the lower its precedence).</p></div>
392 <div class="para"><p>If you wish to affect only a single repository (i.e., to assign
393 attributes to files that are particular to one user's workflow), then
394 attributes should be placed in the <tt>$GIT_DIR/info/attributes</tt> file.
395 Attributes which should be version-controlled and distributed to other
396 repositories (i.e., attributes of interest to all users) should go into
397 <tt>.gitattributes</tt> files.</p></div>
398 <div class="para"><p>Sometimes you would need to override an setting of an attribute
399 for a path to <tt>unspecified</tt> state. This can be done by listing
400 the name of the attribute prefixed with an exclamation point <tt>!</tt>.</p></div>
401 </div>
402 <h2 id="_effects">EFFECTS</h2>
403 <div class="sectionbody">
404 <div class="para"><p>Certain operations by git can be influenced by assigning
405 particular attributes to a path. Currently, the following
406 operations are attributes-aware.</p></div>
407 <h3 id="_checking_out_and_checking_in">Checking-out and checking-in</h3><div style="clear:left"></div>
408 <div class="para"><p>These attributes affect how the contents stored in the
409 repository are copied to the working tree files when commands
410 such as <em>git checkout</em> and <em>git merge</em> run. They also affect how
411 git stores the contents you prepare in the working tree in the
412 repository upon <em>git add</em> and <em>git commit</em>.</p></div>
413 <h4 id="_tt_crlf_tt"><tt>crlf</tt></h4>
414 <div class="para"><p>This attribute controls the line-ending convention.</p></div>
415 <div class="vlist"><dl>
416 <dt>
418 </dt>
419 <dd>
421 Setting the <tt>crlf</tt> attribute on a path is meant to mark
422 the path as a "text" file. <em>core.autocrlf</em> conversion
423 takes place without guessing the content type by
424 inspection.
425 </p>
426 </dd>
427 <dt>
428 Unset
429 </dt>
430 <dd>
432 Unsetting the <tt>crlf</tt> attribute on a path tells git not to
433 attempt any end-of-line conversion upon checkin or checkout.
434 </p>
435 </dd>
436 <dt>
437 Unspecified
438 </dt>
439 <dd>
441 Unspecified <tt>crlf</tt> attribute tells git to apply the
442 <tt>core.autocrlf</tt> conversion when the file content looks
443 like text.
444 </p>
445 </dd>
446 <dt>
447 Set to string value "input"
448 </dt>
449 <dd>
451 This is similar to setting the attribute to <tt>true</tt>, but
452 also forces git to act as if <tt>core.autocrlf</tt> is set to
453 <tt>input</tt> for the path.
454 </p>
455 </dd>
456 </dl></div>
457 <div class="para"><p>Any other value set to <tt>crlf</tt> attribute is ignored and git acts
458 as if the attribute is left unspecified.</p></div>
459 <h4 id="_the_tt_core_autocrlf_tt_conversion">The <tt>core.autocrlf</tt> conversion</h4>
460 <div class="para"><p>If the configuration variable <tt>core.autocrlf</tt> is false, no
461 conversion is done.</p></div>
462 <div class="para"><p>When <tt>core.autocrlf</tt> is true, it means that the platform wants
463 CRLF line endings for files in the working tree, and you want to
464 convert them back to the normal LF line endings when checking
465 in to the repository.</p></div>
466 <div class="para"><p>When <tt>core.autocrlf</tt> is set to "input", line endings are
467 converted to LF upon checkin, but there is no conversion done
468 upon checkout.</p></div>
469 <div class="para"><p>If <tt>core.safecrlf</tt> is set to "true" or "warn", git verifies if
470 the conversion is reversible for the current setting of
471 <tt>core.autocrlf</tt>. For "true", git rejects irreversible
472 conversions; for "warn", git only prints a warning but accepts
473 an irreversible conversion. The safety triggers to prevent such
474 a conversion done to the files in the work tree, but there are a
475 few exceptions. Even though&#8230;</p></div>
476 <div class="ilist"><ul>
477 <li>
479 <em>git add</em> itself does not touch the files in the work tree, the
480 next checkout would, so the safety triggers;
481 </p>
482 </li>
483 <li>
485 <em>git apply</em> to update a text file with a patch does touch the files
486 in the work tree, but the operation is about text files and CRLF
487 conversion is about fixing the line ending inconsistencies, so the
488 safety does not trigger;
489 </p>
490 </li>
491 <li>
493 <em>git diff</em> itself does not touch the files in the work tree, it is
494 often run to inspect the changes you intend to next <em>git add</em>. To
495 catch potential problems early, safety triggers.
496 </p>
497 </li>
498 </ul></div>
499 <h4 id="_tt_ident_tt"><tt>ident</tt></h4>
500 <div class="para"><p>When the attribute <tt>ident</tt> is set for a path, git replaces
501 <tt>$Id$</tt> in the blob object with <tt>$Id:</tt>, followed by the
502 40-character hexadecimal blob object name, followed by a dollar
503 sign <tt>$</tt> upon checkout. Any byte sequence that begins with
504 <tt>$Id:</tt> and ends with <tt>$</tt> in the worktree file is replaced
505 with <tt>$Id$</tt> upon check-in.</p></div>
506 <h4 id="_tt_filter_tt"><tt>filter</tt></h4>
507 <div class="para"><p>A <tt>filter</tt> attribute can be set to a string value that names a
508 filter driver specified in the configuration.</p></div>
509 <div class="para"><p>A filter driver consists of a <tt>clean</tt> command and a <tt>smudge</tt>
510 command, either of which can be left unspecified. Upon
511 checkout, when the <tt>smudge</tt> command is specified, the command is
512 fed the blob object from its standard input, and its standard
513 output is used to update the worktree file. Similarly, the
514 <tt>clean</tt> command is used to convert the contents of worktree file
515 upon checkin.</p></div>
516 <div class="para"><p>A missing filter driver definition in the config is not an error
517 but makes the filter a no-op passthru.</p></div>
518 <div class="para"><p>The content filtering is done to massage the content into a
519 shape that is more convenient for the platform, filesystem, and
520 the user to use. The key phrase here is "more convenient" and not
521 "turning something unusable into usable". In other words, the
522 intent is that if someone unsets the filter driver definition,
523 or does not have the appropriate filter program, the project
524 should still be usable.</p></div>
525 <div class="para"><p>For example, in .gitattributes, you would assign the <tt>filter</tt>
526 attribute for paths.</p></div>
527 <div class="listingblock">
528 <div class="content">
529 <pre><tt>*.c filter=indent</tt></pre>
530 </div></div>
531 <div class="para"><p>Then you would define a "filter.indent.clean" and "filter.indent.smudge"
532 configuration in your .git/config to specify a pair of commands to
533 modify the contents of C programs when the source files are checked
534 in ("clean" is run) and checked out (no change is made because the
535 command is "cat").</p></div>
536 <div class="listingblock">
537 <div class="content">
538 <pre><tt>[filter "indent"]
539 clean = indent
540 smudge = cat</tt></pre>
541 </div></div>
542 <h4 id="_interaction_between_checkin_checkout_attributes">Interaction between checkin/checkout attributes</h4>
543 <div class="para"><p>In the check-in codepath, the worktree file is first converted
544 with <tt>filter</tt> driver (if specified and corresponding driver
545 defined), then the result is processed with <tt>ident</tt> (if
546 specified), and then finally with <tt>crlf</tt> (again, if specified
547 and applicable).</p></div>
548 <div class="para"><p>In the check-out codepath, the blob content is first converted
549 with <tt>crlf</tt>, and then <tt>ident</tt> and fed to <tt>filter</tt>.</p></div>
550 <h3 id="_generating_diff_text">Generating diff text</h3><div style="clear:left"></div>
551 <h4 id="_tt_diff_tt"><tt>diff</tt></h4>
552 <div class="para"><p>The attribute <tt>diff</tt> affects how <em>git</em> generates diffs for particular
553 files. It can tell git whether to generate a textual patch for the path
554 or to treat the path as a binary file. It can also affect what line is
555 shown on the hunk header <tt>@@ -k,l +n,m @@</tt> line, tell git to use an
556 external command to generate the diff, or ask git to convert binary
557 files to a text format before generating the diff.</p></div>
558 <div class="vlist"><dl>
559 <dt>
561 </dt>
562 <dd>
564 A path to which the <tt>diff</tt> attribute is set is treated
565 as text, even when they contain byte values that
566 normally never appear in text files, such as NUL.
567 </p>
568 </dd>
569 <dt>
570 Unset
571 </dt>
572 <dd>
574 A path to which the <tt>diff</tt> attribute is unset will
575 generate <tt>Binary files differ</tt> (or a binary patch, if
576 binary patches are enabled).
577 </p>
578 </dd>
579 <dt>
580 Unspecified
581 </dt>
582 <dd>
584 A path to which the <tt>diff</tt> attribute is unspecified
585 first gets its contents inspected, and if it looks like
586 text, it is treated as text. Otherwise it would
587 generate <tt>Binary files differ</tt>.
588 </p>
589 </dd>
590 <dt>
591 String
592 </dt>
593 <dd>
595 Diff is shown using the specified diff driver. Each driver may
596 specify one or more options, as described in the following
597 section. The options for the diff driver "foo" are defined
598 by the configuration variables in the "diff.foo" section of the
599 git config file.
600 </p>
601 </dd>
602 </dl></div>
603 <h4 id="_defining_an_external_diff_driver">Defining an external diff driver</h4>
604 <div class="para"><p>The definition of a diff driver is done in <tt>gitconfig</tt>, not
605 <tt>gitattributes</tt> file, so strictly speaking this manual page is a
606 wrong place to talk about it. However&#8230;</p></div>
607 <div class="para"><p>To define an external diff driver <tt>jcdiff</tt>, add a section to your
608 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
609 <div class="listingblock">
610 <div class="content">
611 <pre><tt>[diff "jcdiff"]
612 command = j-c-diff</tt></pre>
613 </div></div>
614 <div class="para"><p>When git needs to show you a diff for the path with <tt>diff</tt>
615 attribute set to <tt>jcdiff</tt>, it calls the command you specified
616 with the above configuration, i.e. <tt>j-c-diff</tt>, with 7
617 parameters, just like <tt>GIT_EXTERNAL_DIFF</tt> program is called.
618 See <a href="git.html">git(1)</a> for details.</p></div>
619 <h4 id="_defining_a_custom_hunk_header">Defining a custom hunk-header</h4>
620 <div class="para"><p>Each group of changes (called a "hunk") in the textual diff output
621 is prefixed with a line of the form:</p></div>
622 <div class="literalblock">
623 <div class="content">
624 <pre><tt>@@ -k,l +n,m @@ TEXT</tt></pre>
625 </div></div>
626 <div class="para"><p>This is called a <em>hunk header</em>. The "TEXT" portion is by default a line
627 that begins with an alphabet, an underscore or a dollar sign; this
628 matches what GNU <em>diff -p</em> output uses. This default selection however
629 is not suited for some contents, and you can use a customized pattern
630 to make a selection.</p></div>
631 <div class="para"><p>First, in .gitattributes, you would assign the <tt>diff</tt> attribute
632 for paths.</p></div>
633 <div class="listingblock">
634 <div class="content">
635 <pre><tt>*.tex diff=tex</tt></pre>
636 </div></div>
637 <div class="para"><p>Then, you would define a "diff.tex.xfuncname" configuration to
638 specify a regular expression that matches a line that you would
639 want to appear as the hunk header "TEXT". Add a section to your
640 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
641 <div class="listingblock">
642 <div class="content">
643 <pre><tt>[diff "tex"]
644 xfuncname = "^(\\\\(sub)*section\\{.*)$"</tt></pre>
645 </div></div>
646 <div class="para"><p>Note. A single level of backslashes are eaten by the
647 configuration file parser, so you would need to double the
648 backslashes; the pattern above picks a line that begins with a
649 backslash, and zero or more occurrences of <tt>sub</tt> followed by
650 <tt>section</tt> followed by open brace, to the end of line.</p></div>
651 <div class="para"><p>There are a few built-in patterns to make this easier, and <tt>tex</tt>
652 is one of them, so you do not have to write the above in your
653 configuration file (you still need to enable this with the
654 attribute mechanism, via <tt>.gitattributes</tt>). The following built in
655 patterns are available:</p></div>
656 <div class="ilist"><ul>
657 <li>
659 <tt>bibtex</tt> suitable for files with BibTeX coded references.
660 </p>
661 </li>
662 <li>
664 <tt>cpp</tt> suitable for source code in the C and C++ languages.
665 </p>
666 </li>
667 <li>
669 <tt>html</tt> suitable for HTML/XHTML documents.
670 </p>
671 </li>
672 <li>
674 <tt>java</tt> suitable for source code in the Java language.
675 </p>
676 </li>
677 <li>
679 <tt>objc</tt> suitable for source code in the Objective-C language.
680 </p>
681 </li>
682 <li>
684 <tt>pascal</tt> suitable for source code in the Pascal/Delphi language.
685 </p>
686 </li>
687 <li>
689 <tt>php</tt> suitable for source code in the PHP language.
690 </p>
691 </li>
692 <li>
694 <tt>python</tt> suitable for source code in the Python language.
695 </p>
696 </li>
697 <li>
699 <tt>ruby</tt> suitable for source code in the Ruby language.
700 </p>
701 </li>
702 <li>
704 <tt>tex</tt> suitable for source code for LaTeX documents.
705 </p>
706 </li>
707 </ul></div>
708 <h4 id="_customizing_word_diff">Customizing word diff</h4>
709 <div class="para"><p>You can customize the rules that <tt>git diff --color-words</tt> uses to
710 split words in a line, by specifying an appropriate regular expression
711 in the "diff.*.wordRegex" configuration variable. For example, in TeX
712 a backslash followed by a sequence of letters forms a command, but
713 several such commands can be run together without intervening
714 whitespace. To separate them, use a regular expression in your
715 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
716 <div class="listingblock">
717 <div class="content">
718 <pre><tt>[diff "tex"]
719 wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"</tt></pre>
720 </div></div>
721 <div class="para"><p>A built-in pattern is provided for all languages listed in the
722 previous section.</p></div>
723 <h4 id="_performing_text_diffs_of_binary_files">Performing text diffs of binary files</h4>
724 <div class="para"><p>Sometimes it is desirable to see the diff of a text-converted
725 version of some binary files. For example, a word processor
726 document can be converted to an ASCII text representation, and
727 the diff of the text shown. Even though this conversion loses
728 some information, the resulting diff is useful for human
729 viewing (but cannot be applied directly).</p></div>
730 <div class="para"><p>The <tt>textconv</tt> config option is used to define a program for
731 performing such a conversion. The program should take a single
732 argument, the name of a file to convert, and produce the
733 resulting text on stdout.</p></div>
734 <div class="para"><p>For example, to show the diff of the exif information of a
735 file instead of the binary information (assuming you have the
736 exif tool installed), add the following section to your
737 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file):</p></div>
738 <div class="listingblock">
739 <div class="content">
740 <pre><tt>[diff "jpg"]
741 textconv = exif</tt></pre>
742 </div></div>
743 <div class="admonitionblock">
744 <table><tr>
745 <td class="icon">
746 <div class="title">Note</div>
747 </td>
748 <td class="content">The text conversion is generally a one-way conversion;
749 in this example, we lose the actual image contents and focus
750 just on the text data. This means that diffs generated by
751 textconv are _not_ suitable for applying. For this reason,
752 only <tt>git diff</tt> and the <tt>git log</tt> family of commands (i.e.,
753 log, whatchanged, show) will perform text conversion. <tt>git
754 format-patch</tt> will never generate this output. If you want to
755 send somebody a text-converted diff of a binary file (e.g.,
756 because it quickly conveys the changes you have made), you
757 should generate it separately and send it as a comment _in
758 addition to_ the usual binary diff that you might send.</td>
759 </tr></table>
760 </div>
761 <div class="para"><p>Because text conversion can be slow, especially when doing a
762 large number of them with <tt>git log -p</tt>, git provides a mechanism
763 to cache the output and use it in future diffs. To enable
764 caching, set the "cachetextconv" variable in your diff driver's
765 config. For example:</p></div>
766 <div class="listingblock">
767 <div class="content">
768 <pre><tt>[diff "jpg"]
769 textconv = exif
770 cachetextconv = true</tt></pre>
771 </div></div>
772 <div class="para"><p>This will cache the result of running "exif" on each blob
773 indefinitely. If you change the textconv config variable for a
774 diff driver, git will automatically invalidate the cache entries
775 and re-run the textconv filter. If you want to invalidate the
776 cache manually (e.g., because your version of "exif" was updated
777 and now produces better output), you can remove the cache
778 manually with <tt>git update-ref -d refs/notes/textconv/jpg</tt> (where
779 "jpg" is the name of the diff driver, as in the example above).</p></div>
780 <h3 id="_performing_a_three_way_merge">Performing a three-way merge</h3><div style="clear:left"></div>
781 <h4 id="_tt_merge_tt"><tt>merge</tt></h4>
782 <div class="para"><p>The attribute <tt>merge</tt> affects how three versions of a file is
783 merged when a file-level merge is necessary during <tt>git merge</tt>,
784 and other commands such as <tt>git revert</tt> and <tt>git cherry-pick</tt>.</p></div>
785 <div class="vlist"><dl>
786 <dt>
788 </dt>
789 <dd>
791 Built-in 3-way merge driver is used to merge the
792 contents in a way similar to <em>merge</em> command of <tt>RCS</tt>
793 suite. This is suitable for ordinary text files.
794 </p>
795 </dd>
796 <dt>
797 Unset
798 </dt>
799 <dd>
801 Take the version from the current branch as the
802 tentative merge result, and declare that the merge has
803 conflicts. This is suitable for binary files that does
804 not have a well-defined merge semantics.
805 </p>
806 </dd>
807 <dt>
808 Unspecified
809 </dt>
810 <dd>
812 By default, this uses the same built-in 3-way merge
813 driver as is the case the <tt>merge</tt> attribute is set.
814 However, <tt>merge.default</tt> configuration variable can name
815 different merge driver to be used for paths to which the
816 <tt>merge</tt> attribute is unspecified.
817 </p>
818 </dd>
819 <dt>
820 String
821 </dt>
822 <dd>
824 3-way merge is performed using the specified custom
825 merge driver. The built-in 3-way merge driver can be
826 explicitly specified by asking for "text" driver; the
827 built-in "take the current branch" driver can be
828 requested with "binary".
829 </p>
830 </dd>
831 </dl></div>
832 <h4 id="_built_in_merge_drivers">Built-in merge drivers</h4>
833 <div class="para"><p>There are a few built-in low-level merge drivers defined that
834 can be asked for via the <tt>merge</tt> attribute.</p></div>
835 <div class="vlist"><dl>
836 <dt>
837 text
838 </dt>
839 <dd>
841 Usual 3-way file level merge for text files. Conflicted
842 regions are marked with conflict markers <tt>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</tt>,
843 <tt>=======</tt> and <tt>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</tt>. The version from your branch
844 appears before the <tt>=======</tt> marker, and the version
845 from the merged branch appears after the <tt>=======</tt>
846 marker.
847 </p>
848 </dd>
849 <dt>
850 binary
851 </dt>
852 <dd>
854 Keep the version from your branch in the work tree, but
855 leave the path in the conflicted state for the user to
856 sort out.
857 </p>
858 </dd>
859 <dt>
860 union
861 </dt>
862 <dd>
864 Run 3-way file level merge for text files, but take
865 lines from both versions, instead of leaving conflict
866 markers. This tends to leave the added lines in the
867 resulting file in random order and the user should
868 verify the result. Do not use this if you do not
869 understand the implications.
870 </p>
871 </dd>
872 </dl></div>
873 <h4 id="_defining_a_custom_merge_driver">Defining a custom merge driver</h4>
874 <div class="para"><p>The definition of a merge driver is done in the <tt>.git/config</tt>
875 file, not in the <tt>gitattributes</tt> file, so strictly speaking this
876 manual page is a wrong place to talk about it. However&#8230;</p></div>
877 <div class="para"><p>To define a custom merge driver <tt>filfre</tt>, add a section to your
878 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
879 <div class="listingblock">
880 <div class="content">
881 <pre><tt>[merge "filfre"]
882 name = feel-free merge driver
883 driver = filfre %O %A %B
884 recursive = binary</tt></pre>
885 </div></div>
886 <div class="para"><p>The <tt>merge.*.name</tt> variable gives the driver a human-readable
887 name.</p></div>
888 <div class="para"><p>The <tt>merge.*.driver</tt> variable's value is used to construct a
889 command to run to merge ancestor's version (<tt>%O</tt>), current
890 version (<tt>%A</tt>) and the other branches' version (<tt>%B</tt>). These
891 three tokens are replaced with the names of temporary files that
892 hold the contents of these versions when the command line is
893 built. Additionally, %L will be replaced with the conflict marker
894 size (see below).</p></div>
895 <div class="para"><p>The merge driver is expected to leave the result of the merge in
896 the file named with <tt>%A</tt> by overwriting it, and exit with zero
897 status if it managed to merge them cleanly, or non-zero if there
898 were conflicts.</p></div>
899 <div class="para"><p>The <tt>merge.*.recursive</tt> variable specifies what other merge
900 driver to use when the merge driver is called for an internal
901 merge between common ancestors, when there are more than one.
902 When left unspecified, the driver itself is used for both
903 internal merge and the final merge.</p></div>
904 <h4 id="_tt_conflict_marker_size_tt"><tt>conflict-marker-size</tt></h4>
905 <div class="para"><p>This attribute controls the length of conflict markers left in
906 the work tree file during a conflicted merge. Only setting to
907 the value to a positive integer has any meaningful effect.</p></div>
908 <div class="para"><p>For example, this line in <tt>.gitattributes</tt> can be used to tell the merge
909 machinery to leave much longer (instead of the usual 7-character-long)
910 conflict markers when merging the file <tt>Documentation/git-merge.txt</tt>
911 results in a conflict.</p></div>
912 <div class="listingblock">
913 <div class="content">
914 <pre><tt>Documentation/git-merge.txt conflict-marker-size=32</tt></pre>
915 </div></div>
916 <h3 id="_checking_whitespace_errors">Checking whitespace errors</h3><div style="clear:left"></div>
917 <h4 id="_tt_whitespace_tt"><tt>whitespace</tt></h4>
918 <div class="para"><p>The <tt>core.whitespace</tt> configuration variable allows you to define what
919 <em>diff</em> and <em>apply</em> should consider whitespace errors for all paths in
920 the project (See <a href="git-config.html">git-config(1)</a>). This attribute gives you finer
921 control per path.</p></div>
922 <div class="vlist"><dl>
923 <dt>
925 </dt>
926 <dd>
928 Notice all types of potential whitespace errors known to git.
929 </p>
930 </dd>
931 <dt>
932 Unset
933 </dt>
934 <dd>
936 Do not notice anything as error.
937 </p>
938 </dd>
939 <dt>
940 Unspecified
941 </dt>
942 <dd>
944 Use the value of <tt>core.whitespace</tt> configuration variable to
945 decide what to notice as error.
946 </p>
947 </dd>
948 <dt>
949 String
950 </dt>
951 <dd>
953 Specify a comma separate list of common whitespace problems to
954 notice in the same format as <tt>core.whitespace</tt> configuration
955 variable.
956 </p>
957 </dd>
958 </dl></div>
959 <h3 id="_creating_an_archive">Creating an archive</h3><div style="clear:left"></div>
960 <h4 id="_tt_export_ignore_tt"><tt>export-ignore</tt></h4>
961 <div class="para"><p>Files and directories with the attribute <tt>export-ignore</tt> won't be added to
962 archive files.</p></div>
963 <h4 id="_tt_export_subst_tt"><tt>export-subst</tt></h4>
964 <div class="para"><p>If the attribute <tt>export-subst</tt> is set for a file then git will expand
965 several placeholders when adding this file to an archive. The
966 expansion depends on the availability of a commit ID, i.e., if
967 <a href="git-archive.html">git-archive(1)</a> has been given a tree instead of a commit or a
968 tag then no replacement will be done. The placeholders are the same
969 as those for the option <tt>--pretty=format:</tt> of <a href="git-log.html">git-log(1)</a>,
970 except that they need to be wrapped like this: <tt>$Format:PLACEHOLDERS$</tt>
971 in the file. E.g. the string <tt>$Format:%H$</tt> will be replaced by the
972 commit hash.</p></div>
973 <h3 id="_packing_objects">Packing objects</h3><div style="clear:left"></div>
974 <h4 id="_tt_delta_tt"><tt>delta</tt></h4>
975 <div class="para"><p>Delta compression will not be attempted for blobs for paths with the
976 attribute <tt>delta</tt> set to false.</p></div>
977 <h3 id="_viewing_files_in_gui_tools">Viewing files in GUI tools</h3><div style="clear:left"></div>
978 <h4 id="_tt_encoding_tt"><tt>encoding</tt></h4>
979 <div class="para"><p>The value of this attribute specifies the character encoding that should
980 be used by GUI tools (e.g. <a href="gitk.html">gitk(1)</a> and <a href="git-gui.html">git-gui(1)</a>) to
981 display the contents of the relevant file. Note that due to performance
982 considerations <a href="gitk.html">gitk(1)</a> does not use this attribute unless you
983 manually enable per-file encodings in its options.</p></div>
984 <div class="para"><p>If this attribute is not set or has an invalid value, the value of the
985 <tt>gui.encoding</tt> configuration variable is used instead
986 (See <a href="git-config.html">git-config(1)</a>).</p></div>
987 </div>
988 <h2 id="_using_attribute_macros">USING ATTRIBUTE MACROS</h2>
989 <div class="sectionbody">
990 <div class="para"><p>You do not want any end-of-line conversions applied to, nor textual diffs
991 produced for, any binary file you track. You would need to specify e.g.</p></div>
992 <div class="listingblock">
993 <div class="content">
994 <pre><tt>*.jpg -crlf -diff</tt></pre>
995 </div></div>
996 <div class="para"><p>but that may become cumbersome, when you have many attributes. Using
997 attribute macros, you can specify groups of attributes set or unset at
998 the same time. The system knows a built-in attribute macro, <tt>binary</tt>:</p></div>
999 <div class="listingblock">
1000 <div class="content">
1001 <pre><tt>*.jpg binary</tt></pre>
1002 </div></div>
1003 <div class="para"><p>which is equivalent to the above. Note that the attribute macros can only
1004 be "Set" (see the above example that sets "binary" macro as if it were an
1005 ordinary attribute --- setting it in turn unsets "crlf" and "diff").</p></div>
1006 </div>
1007 <h2 id="_defining_attribute_macros">DEFINING ATTRIBUTE MACROS</h2>
1008 <div class="sectionbody">
1009 <div class="para"><p>Custom attribute macros can be defined only in the <tt>.gitattributes</tt> file
1010 at the toplevel (i.e. not in any subdirectory). The built-in attribute
1011 macro "binary" is equivalent to:</p></div>
1012 <div class="listingblock">
1013 <div class="content">
1014 <pre><tt>[attr]binary -diff -crlf</tt></pre>
1015 </div></div>
1016 </div>
1017 <h2 id="_example">EXAMPLE</h2>
1018 <div class="sectionbody">
1019 <div class="para"><p>If you have these three <tt>gitattributes</tt> file:</p></div>
1020 <div class="listingblock">
1021 <div class="content">
1022 <pre><tt>(in $GIT_DIR/info/attributes)
1024 a* foo !bar -baz
1026 (in .gitattributes)
1027 abc foo bar baz
1029 (in t/.gitattributes)
1030 ab* merge=filfre
1031 abc -foo -bar
1032 *.c frotz</tt></pre>
1033 </div></div>
1034 <div class="para"><p>the attributes given to path <tt>t/abc</tt> are computed as follows:</p></div>
1035 <div class="olist"><ol>
1036 <li>
1038 By examining <tt>t/.gitattributes</tt> (which is in the same
1039 directory as the path in question), git finds that the first
1040 line matches. <tt>merge</tt> attribute is set. It also finds that
1041 the second line matches, and attributes <tt>foo</tt> and <tt>bar</tt>
1042 are unset.
1043 </p>
1044 </li>
1045 <li>
1047 Then it examines <tt>.gitattributes</tt> (which is in the parent
1048 directory), and finds that the first line matches, but
1049 <tt>t/.gitattributes</tt> file already decided how <tt>merge</tt>, <tt>foo</tt>
1050 and <tt>bar</tt> attributes should be given to this path, so it
1051 leaves <tt>foo</tt> and <tt>bar</tt> unset. Attribute <tt>baz</tt> is set.
1052 </p>
1053 </li>
1054 <li>
1056 Finally it examines <tt>$GIT_DIR/info/attributes</tt>. This file
1057 is used to override the in-tree settings. The first line is
1058 a match, and <tt>foo</tt> is set, <tt>bar</tt> is reverted to unspecified
1059 state, and <tt>baz</tt> is unset.
1060 </p>
1061 </li>
1062 </ol></div>
1063 <div class="para"><p>As the result, the attributes assignment to <tt>t/abc</tt> becomes:</p></div>
1064 <div class="listingblock">
1065 <div class="content">
1066 <pre><tt>foo set to true
1067 bar unspecified
1068 baz set to false
1069 merge set to string value "filfre"
1070 frotz unspecified</tt></pre>
1071 </div></div>
1072 </div>
1073 <h2 id="_git">GIT</h2>
1074 <div class="sectionbody">
1075 <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1076 </div>
1077 <div id="footer">
1078 <div id="footer-text">
1079 Last updated 2010-05-09 07:24:21 UTC
1080 </div>
1081 </div>
1082 </body>
1083 </html>