Autogenerated HTML docs for v1.7.3-rc0-38-g9ab5a
[git/jnareb-git.git] / gitattributes.html
blob8df0fe024665234cae2cdda92801950fb8951e38
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_text_tt"><tt>text</tt></h4>
414 <div class="para"><p>This attribute enables and controls end-of-line normalization. When a
415 text file is normalized, its line endings are converted to LF in the
416 repository. To control what line ending style is used in the working
417 directory, use the <tt>eol</tt> attribute for a single file and the
418 <tt>core.eol</tt> configuration variable for all text files.</p></div>
419 <div class="vlist"><dl>
420 <dt>
422 </dt>
423 <dd>
425 Setting the <tt>text</tt> attribute on a path enables end-of-line
426 normalization and marks the path as a text file. End-of-line
427 conversion takes place without guessing the content type.
428 </p>
429 </dd>
430 <dt>
431 Unset
432 </dt>
433 <dd>
435 Unsetting the <tt>text</tt> attribute on a path tells git not to
436 attempt any end-of-line conversion upon checkin or checkout.
437 </p>
438 </dd>
439 <dt>
440 Set to string value "auto"
441 </dt>
442 <dd>
444 When <tt>text</tt> is set to "auto", the path is marked for automatic
445 end-of-line normalization. If git decides that the content is
446 text, its line endings are normalized to LF on checkin.
447 </p>
448 </dd>
449 <dt>
450 Unspecified
451 </dt>
452 <dd>
454 If the <tt>text</tt> attribute is unspecified, git uses the
455 <tt>core.autocrlf</tt> configuration variable to determine if the
456 file should be converted.
457 </p>
458 </dd>
459 </dl></div>
460 <div class="para"><p>Any other value causes git to act as if <tt>text</tt> has been left
461 unspecified.</p></div>
462 <h4 id="_tt_eol_tt"><tt>eol</tt></h4>
463 <div class="para"><p>This attribute sets a specific line-ending style to be used in the
464 working directory. It enables end-of-line normalization without any
465 content checks, effectively setting the <tt>text</tt> attribute.</p></div>
466 <div class="vlist"><dl>
467 <dt>
468 Set to string value "crlf"
469 </dt>
470 <dd>
472 This setting forces git to normalize line endings for this
473 file on checkin and convert them to CRLF when the file is
474 checked out.
475 </p>
476 </dd>
477 <dt>
478 Set to string value "lf"
479 </dt>
480 <dd>
482 This setting forces git to normalize line endings to LF on
483 checkin and prevents conversion to CRLF when the file is
484 checked out.
485 </p>
486 </dd>
487 </dl></div>
488 <h4 id="_backwards_compatibility_with_tt_crlf_tt_attribute">Backwards compatibility with <tt>crlf</tt> attribute</h4>
489 <div class="para"><p>For backwards compatibility, the <tt>crlf</tt> attribute is interpreted as
490 follows:</p></div>
491 <div class="listingblock">
492 <div class="content">
493 <pre><tt>crlf text
494 -crlf -text
495 crlf=input eol=lf</tt></pre>
496 </div></div>
497 <h4 id="_end_of_line_conversion">End-of-line conversion</h4>
498 <div class="para"><p>While git normally leaves file contents alone, it can be configured to
499 normalize line endings to LF in the repository and, optionally, to
500 convert them to CRLF when files are checked out.</p></div>
501 <div class="para"><p>Here is an example that will make git normalize .txt, .vcproj and .sh
502 files, ensure that .vcproj files have CRLF and .sh files have LF in
503 the working directory, and prevent .jpg files from being normalized
504 regardless of their content.</p></div>
505 <div class="listingblock">
506 <div class="content">
507 <pre><tt>*.txt text
508 *.vcproj eol=crlf
509 *.sh eol=lf
510 *.jpg -text</tt></pre>
511 </div></div>
512 <div class="para"><p>Other source code management systems normalize all text files in their
513 repositories, and there are two ways to enable similar automatic
514 normalization in git.</p></div>
515 <div class="para"><p>If you simply want to have CRLF line endings in your working directory
516 regardless of the repository you are working with, you can set the
517 config variable "core.autocrlf" without changing any attributes.</p></div>
518 <div class="listingblock">
519 <div class="content">
520 <pre><tt>[core]
521 autocrlf = true</tt></pre>
522 </div></div>
523 <div class="para"><p>This does not force normalization of all text files, but does ensure
524 that text files that you introduce to the repository have their line
525 endings normalized to LF when they are added, and that files that are
526 already normalized in the repository stay normalized.</p></div>
527 <div class="para"><p>If you want to interoperate with a source code management system that
528 enforces end-of-line normalization, or you simply want all text files
529 in your repository to be normalized, you should instead set the <tt>text</tt>
530 attribute to "auto" for _all_ files.</p></div>
531 <div class="listingblock">
532 <div class="content">
533 <pre><tt>* text=auto</tt></pre>
534 </div></div>
535 <div class="para"><p>This ensures that all files that git considers to be text will have
536 normalized (LF) line endings in the repository. The <tt>core.eol</tt>
537 configuration variable controls which line endings git will use for
538 normalized files in your working directory; the default is to use the
539 native line ending for your platform, or CRLF if <tt>core.autocrlf</tt> is
540 set.</p></div>
541 <div class="admonitionblock">
542 <table><tr>
543 <td class="icon">
544 <div class="title">Note</div>
545 </td>
546 <td class="content">When <tt>text=auto</tt> normalization is enabled in an existing
547 repository, any text files containing CRLFs should be normalized. If
548 they are not they will be normalized the next time someone tries to
549 change them, causing unfortunate misattribution. From a clean working
550 directory:</td>
551 </tr></table>
552 </div>
553 <div class="listingblock">
554 <div class="content">
555 <pre><tt>$ echo "* text=auto" &gt;&gt;.gitattributes
556 $ rm .git/index # Remove the index to force git to
557 $ git reset # re-scan the working directory
558 $ git status # Show files that will be normalized
559 $ git add -u
560 $ git add .gitattributes
561 $ git commit -m "Introduce end-of-line normalization"</tt></pre>
562 </div></div>
563 <div class="para"><p>If any files that should not be normalized show up in <em>git status</em>,
564 unset their <tt>text</tt> attribute before running <em>git add -u</em>.</p></div>
565 <div class="listingblock">
566 <div class="content">
567 <pre><tt>manual.pdf -text</tt></pre>
568 </div></div>
569 <div class="para"><p>Conversely, text files that git does not detect can have normalization
570 enabled manually.</p></div>
571 <div class="listingblock">
572 <div class="content">
573 <pre><tt>weirdchars.txt text</tt></pre>
574 </div></div>
575 <div class="para"><p>If <tt>core.safecrlf</tt> is set to "true" or "warn", git verifies if
576 the conversion is reversible for the current setting of
577 <tt>core.autocrlf</tt>. For "true", git rejects irreversible
578 conversions; for "warn", git only prints a warning but accepts
579 an irreversible conversion. The safety triggers to prevent such
580 a conversion done to the files in the work tree, but there are a
581 few exceptions. Even though&#8230;</p></div>
582 <div class="ilist"><ul>
583 <li>
585 <em>git add</em> itself does not touch the files in the work tree, the
586 next checkout would, so the safety triggers;
587 </p>
588 </li>
589 <li>
591 <em>git apply</em> to update a text file with a patch does touch the files
592 in the work tree, but the operation is about text files and CRLF
593 conversion is about fixing the line ending inconsistencies, so the
594 safety does not trigger;
595 </p>
596 </li>
597 <li>
599 <em>git diff</em> itself does not touch the files in the work tree, it is
600 often run to inspect the changes you intend to next <em>git add</em>. To
601 catch potential problems early, safety triggers.
602 </p>
603 </li>
604 </ul></div>
605 <h4 id="_tt_ident_tt"><tt>ident</tt></h4>
606 <div class="para"><p>When the attribute <tt>ident</tt> is set for a path, git replaces
607 <tt>$Id$</tt> in the blob object with <tt>$Id:</tt>, followed by the
608 40-character hexadecimal blob object name, followed by a dollar
609 sign <tt>$</tt> upon checkout. Any byte sequence that begins with
610 <tt>$Id:</tt> and ends with <tt>$</tt> in the worktree file is replaced
611 with <tt>$Id$</tt> upon check-in.</p></div>
612 <h4 id="_tt_filter_tt"><tt>filter</tt></h4>
613 <div class="para"><p>A <tt>filter</tt> attribute can be set to a string value that names a
614 filter driver specified in the configuration.</p></div>
615 <div class="para"><p>A filter driver consists of a <tt>clean</tt> command and a <tt>smudge</tt>
616 command, either of which can be left unspecified. Upon
617 checkout, when the <tt>smudge</tt> command is specified, the command is
618 fed the blob object from its standard input, and its standard
619 output is used to update the worktree file. Similarly, the
620 <tt>clean</tt> command is used to convert the contents of worktree file
621 upon checkin.</p></div>
622 <div class="para"><p>A missing filter driver definition in the config is not an error
623 but makes the filter a no-op passthru.</p></div>
624 <div class="para"><p>The content filtering is done to massage the content into a
625 shape that is more convenient for the platform, filesystem, and
626 the user to use. The key phrase here is "more convenient" and not
627 "turning something unusable into usable". In other words, the
628 intent is that if someone unsets the filter driver definition,
629 or does not have the appropriate filter program, the project
630 should still be usable.</p></div>
631 <div class="para"><p>For example, in .gitattributes, you would assign the <tt>filter</tt>
632 attribute for paths.</p></div>
633 <div class="listingblock">
634 <div class="content">
635 <pre><tt>*.c filter=indent</tt></pre>
636 </div></div>
637 <div class="para"><p>Then you would define a "filter.indent.clean" and "filter.indent.smudge"
638 configuration in your .git/config to specify a pair of commands to
639 modify the contents of C programs when the source files are checked
640 in ("clean" is run) and checked out (no change is made because the
641 command is "cat").</p></div>
642 <div class="listingblock">
643 <div class="content">
644 <pre><tt>[filter "indent"]
645 clean = indent
646 smudge = cat</tt></pre>
647 </div></div>
648 <div class="para"><p>For best results, <tt>clean</tt> should not alter its output further if it is
649 run twice ("clean-&gt;clean" should be equivalent to "clean"), and
650 multiple <tt>smudge</tt> commands should not alter <tt>clean</tt>'s output
651 ("smudge-&gt;smudge-&gt;clean" should be equivalent to "clean"). See the
652 section on merging below.</p></div>
653 <div class="para"><p>The "indent" filter is well-behaved in this regard: it will not modify
654 input that is already correctly indented. In this case, the lack of a
655 smudge filter means that the clean filter _must_ accept its own output
656 without modifying it.</p></div>
657 <h4 id="_interaction_between_checkin_checkout_attributes">Interaction between checkin/checkout attributes</h4>
658 <div class="para"><p>In the check-in codepath, the worktree file is first converted
659 with <tt>filter</tt> driver (if specified and corresponding driver
660 defined), then the result is processed with <tt>ident</tt> (if
661 specified), and then finally with <tt>text</tt> (again, if specified
662 and applicable).</p></div>
663 <div class="para"><p>In the check-out codepath, the blob content is first converted
664 with <tt>text</tt>, and then <tt>ident</tt> and fed to <tt>filter</tt>.</p></div>
665 <h4 id="_merging_branches_with_differing_checkin_checkout_attributes">Merging branches with differing checkin/checkout attributes</h4>
666 <div class="para"><p>If you have added attributes to a file that cause the canonical
667 repository format for that file to change, such as adding a
668 clean/smudge filter or text/eol/ident attributes, merging anything
669 where the attribute is not in place would normally cause merge
670 conflicts.</p></div>
671 <div class="para"><p>To prevent these unnecessary merge conflicts, git can be told to run a
672 virtual check-out and check-in of all three stages of a file when
673 resolving a three-way merge by setting the <tt>merge.renormalize</tt>
674 configuration variable. This prevents changes caused by check-in
675 conversion from causing spurious merge conflicts when a converted file
676 is merged with an unconverted file.</p></div>
677 <div class="para"><p>As long as a "smudge-&gt;clean" results in the same output as a "clean"
678 even on files that are already smudged, this strategy will
679 automatically resolve all filter-related conflicts. Filters that do
680 not act in this way may cause additional merge conflicts that must be
681 resolved manually.</p></div>
682 <h3 id="_generating_diff_text">Generating diff text</h3><div style="clear:left"></div>
683 <h4 id="_tt_diff_tt"><tt>diff</tt></h4>
684 <div class="para"><p>The attribute <tt>diff</tt> affects how <em>git</em> generates diffs for particular
685 files. It can tell git whether to generate a textual patch for the path
686 or to treat the path as a binary file. It can also affect what line is
687 shown on the hunk header <tt>@@ -k,l +n,m @@</tt> line, tell git to use an
688 external command to generate the diff, or ask git to convert binary
689 files to a text format before generating the diff.</p></div>
690 <div class="vlist"><dl>
691 <dt>
693 </dt>
694 <dd>
696 A path to which the <tt>diff</tt> attribute is set is treated
697 as text, even when they contain byte values that
698 normally never appear in text files, such as NUL.
699 </p>
700 </dd>
701 <dt>
702 Unset
703 </dt>
704 <dd>
706 A path to which the <tt>diff</tt> attribute is unset will
707 generate <tt>Binary files differ</tt> (or a binary patch, if
708 binary patches are enabled).
709 </p>
710 </dd>
711 <dt>
712 Unspecified
713 </dt>
714 <dd>
716 A path to which the <tt>diff</tt> attribute is unspecified
717 first gets its contents inspected, and if it looks like
718 text, it is treated as text. Otherwise it would
719 generate <tt>Binary files differ</tt>.
720 </p>
721 </dd>
722 <dt>
723 String
724 </dt>
725 <dd>
727 Diff is shown using the specified diff driver. Each driver may
728 specify one or more options, as described in the following
729 section. The options for the diff driver "foo" are defined
730 by the configuration variables in the "diff.foo" section of the
731 git config file.
732 </p>
733 </dd>
734 </dl></div>
735 <h4 id="_defining_an_external_diff_driver">Defining an external diff driver</h4>
736 <div class="para"><p>The definition of a diff driver is done in <tt>gitconfig</tt>, not
737 <tt>gitattributes</tt> file, so strictly speaking this manual page is a
738 wrong place to talk about it. However&#8230;</p></div>
739 <div class="para"><p>To define an external diff driver <tt>jcdiff</tt>, add a section to your
740 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
741 <div class="listingblock">
742 <div class="content">
743 <pre><tt>[diff "jcdiff"]
744 command = j-c-diff</tt></pre>
745 </div></div>
746 <div class="para"><p>When git needs to show you a diff for the path with <tt>diff</tt>
747 attribute set to <tt>jcdiff</tt>, it calls the command you specified
748 with the above configuration, i.e. <tt>j-c-diff</tt>, with 7
749 parameters, just like <tt>GIT_EXTERNAL_DIFF</tt> program is called.
750 See <a href="git.html">git(1)</a> for details.</p></div>
751 <h4 id="_defining_a_custom_hunk_header">Defining a custom hunk-header</h4>
752 <div class="para"><p>Each group of changes (called a "hunk") in the textual diff output
753 is prefixed with a line of the form:</p></div>
754 <div class="literalblock">
755 <div class="content">
756 <pre><tt>@@ -k,l +n,m @@ TEXT</tt></pre>
757 </div></div>
758 <div class="para"><p>This is called a <em>hunk header</em>. The "TEXT" portion is by default a line
759 that begins with an alphabet, an underscore or a dollar sign; this
760 matches what GNU <em>diff -p</em> output uses. This default selection however
761 is not suited for some contents, and you can use a customized pattern
762 to make a selection.</p></div>
763 <div class="para"><p>First, in .gitattributes, you would assign the <tt>diff</tt> attribute
764 for paths.</p></div>
765 <div class="listingblock">
766 <div class="content">
767 <pre><tt>*.tex diff=tex</tt></pre>
768 </div></div>
769 <div class="para"><p>Then, you would define a "diff.tex.xfuncname" configuration to
770 specify a regular expression that matches a line that you would
771 want to appear as the hunk header "TEXT". Add a section to your
772 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
773 <div class="listingblock">
774 <div class="content">
775 <pre><tt>[diff "tex"]
776 xfuncname = "^(\\\\(sub)*section\\{.*)$"</tt></pre>
777 </div></div>
778 <div class="para"><p>Note. A single level of backslashes are eaten by the
779 configuration file parser, so you would need to double the
780 backslashes; the pattern above picks a line that begins with a
781 backslash, and zero or more occurrences of <tt>sub</tt> followed by
782 <tt>section</tt> followed by open brace, to the end of line.</p></div>
783 <div class="para"><p>There are a few built-in patterns to make this easier, and <tt>tex</tt>
784 is one of them, so you do not have to write the above in your
785 configuration file (you still need to enable this with the
786 attribute mechanism, via <tt>.gitattributes</tt>). The following built in
787 patterns are available:</p></div>
788 <div class="ilist"><ul>
789 <li>
791 <tt>bibtex</tt> suitable for files with BibTeX coded references.
792 </p>
793 </li>
794 <li>
796 <tt>cpp</tt> suitable for source code in the C and C++ languages.
797 </p>
798 </li>
799 <li>
801 <tt>csharp</tt> suitable for source code in the C# language.
802 </p>
803 </li>
804 <li>
806 <tt>html</tt> suitable for HTML/XHTML documents.
807 </p>
808 </li>
809 <li>
811 <tt>java</tt> suitable for source code in the Java language.
812 </p>
813 </li>
814 <li>
816 <tt>objc</tt> suitable for source code in the Objective-C language.
817 </p>
818 </li>
819 <li>
821 <tt>pascal</tt> suitable for source code in the Pascal/Delphi language.
822 </p>
823 </li>
824 <li>
826 <tt>php</tt> suitable for source code in the PHP language.
827 </p>
828 </li>
829 <li>
831 <tt>python</tt> suitable for source code in the Python language.
832 </p>
833 </li>
834 <li>
836 <tt>ruby</tt> suitable for source code in the Ruby language.
837 </p>
838 </li>
839 <li>
841 <tt>tex</tt> suitable for source code for LaTeX documents.
842 </p>
843 </li>
844 </ul></div>
845 <h4 id="_customizing_word_diff">Customizing word diff</h4>
846 <div class="para"><p>You can customize the rules that <tt>git diff --word-diff</tt> uses to
847 split words in a line, by specifying an appropriate regular expression
848 in the "diff.*.wordRegex" configuration variable. For example, in TeX
849 a backslash followed by a sequence of letters forms a command, but
850 several such commands can be run together without intervening
851 whitespace. To separate them, use a regular expression in your
852 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
853 <div class="listingblock">
854 <div class="content">
855 <pre><tt>[diff "tex"]
856 wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"</tt></pre>
857 </div></div>
858 <div class="para"><p>A built-in pattern is provided for all languages listed in the
859 previous section.</p></div>
860 <h4 id="_performing_text_diffs_of_binary_files">Performing text diffs of binary files</h4>
861 <div class="para"><p>Sometimes it is desirable to see the diff of a text-converted
862 version of some binary files. For example, a word processor
863 document can be converted to an ASCII text representation, and
864 the diff of the text shown. Even though this conversion loses
865 some information, the resulting diff is useful for human
866 viewing (but cannot be applied directly).</p></div>
867 <div class="para"><p>The <tt>textconv</tt> config option is used to define a program for
868 performing such a conversion. The program should take a single
869 argument, the name of a file to convert, and produce the
870 resulting text on stdout.</p></div>
871 <div class="para"><p>For example, to show the diff of the exif information of a
872 file instead of the binary information (assuming you have the
873 exif tool installed), add the following section to your
874 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file):</p></div>
875 <div class="listingblock">
876 <div class="content">
877 <pre><tt>[diff "jpg"]
878 textconv = exif</tt></pre>
879 </div></div>
880 <div class="admonitionblock">
881 <table><tr>
882 <td class="icon">
883 <div class="title">Note</div>
884 </td>
885 <td class="content">The text conversion is generally a one-way conversion;
886 in this example, we lose the actual image contents and focus
887 just on the text data. This means that diffs generated by
888 textconv are _not_ suitable for applying. For this reason,
889 only <tt>git diff</tt> and the <tt>git log</tt> family of commands (i.e.,
890 log, whatchanged, show) will perform text conversion. <tt>git
891 format-patch</tt> will never generate this output. If you want to
892 send somebody a text-converted diff of a binary file (e.g.,
893 because it quickly conveys the changes you have made), you
894 should generate it separately and send it as a comment _in
895 addition to_ the usual binary diff that you might send.</td>
896 </tr></table>
897 </div>
898 <div class="para"><p>Because text conversion can be slow, especially when doing a
899 large number of them with <tt>git log -p</tt>, git provides a mechanism
900 to cache the output and use it in future diffs. To enable
901 caching, set the "cachetextconv" variable in your diff driver's
902 config. For example:</p></div>
903 <div class="listingblock">
904 <div class="content">
905 <pre><tt>[diff "jpg"]
906 textconv = exif
907 cachetextconv = true</tt></pre>
908 </div></div>
909 <div class="para"><p>This will cache the result of running "exif" on each blob
910 indefinitely. If you change the textconv config variable for a
911 diff driver, git will automatically invalidate the cache entries
912 and re-run the textconv filter. If you want to invalidate the
913 cache manually (e.g., because your version of "exif" was updated
914 and now produces better output), you can remove the cache
915 manually with <tt>git update-ref -d refs/notes/textconv/jpg</tt> (where
916 "jpg" is the name of the diff driver, as in the example above).</p></div>
917 <h3 id="_performing_a_three_way_merge">Performing a three-way merge</h3><div style="clear:left"></div>
918 <h4 id="_tt_merge_tt"><tt>merge</tt></h4>
919 <div class="para"><p>The attribute <tt>merge</tt> affects how three versions of a file is
920 merged when a file-level merge is necessary during <tt>git merge</tt>,
921 and other commands such as <tt>git revert</tt> and <tt>git cherry-pick</tt>.</p></div>
922 <div class="vlist"><dl>
923 <dt>
925 </dt>
926 <dd>
928 Built-in 3-way merge driver is used to merge the
929 contents in a way similar to <em>merge</em> command of <tt>RCS</tt>
930 suite. This is suitable for ordinary text files.
931 </p>
932 </dd>
933 <dt>
934 Unset
935 </dt>
936 <dd>
938 Take the version from the current branch as the
939 tentative merge result, and declare that the merge has
940 conflicts. This is suitable for binary files that does
941 not have a well-defined merge semantics.
942 </p>
943 </dd>
944 <dt>
945 Unspecified
946 </dt>
947 <dd>
949 By default, this uses the same built-in 3-way merge
950 driver as is the case the <tt>merge</tt> attribute is set.
951 However, <tt>merge.default</tt> configuration variable can name
952 different merge driver to be used for paths to which the
953 <tt>merge</tt> attribute is unspecified.
954 </p>
955 </dd>
956 <dt>
957 String
958 </dt>
959 <dd>
961 3-way merge is performed using the specified custom
962 merge driver. The built-in 3-way merge driver can be
963 explicitly specified by asking for "text" driver; the
964 built-in "take the current branch" driver can be
965 requested with "binary".
966 </p>
967 </dd>
968 </dl></div>
969 <h4 id="_built_in_merge_drivers">Built-in merge drivers</h4>
970 <div class="para"><p>There are a few built-in low-level merge drivers defined that
971 can be asked for via the <tt>merge</tt> attribute.</p></div>
972 <div class="vlist"><dl>
973 <dt>
974 text
975 </dt>
976 <dd>
978 Usual 3-way file level merge for text files. Conflicted
979 regions are marked with conflict markers <tt>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</tt>,
980 <tt>=======</tt> and <tt>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</tt>. The version from your branch
981 appears before the <tt>=======</tt> marker, and the version
982 from the merged branch appears after the <tt>=======</tt>
983 marker.
984 </p>
985 </dd>
986 <dt>
987 binary
988 </dt>
989 <dd>
991 Keep the version from your branch in the work tree, but
992 leave the path in the conflicted state for the user to
993 sort out.
994 </p>
995 </dd>
996 <dt>
997 union
998 </dt>
999 <dd>
1001 Run 3-way file level merge for text files, but take
1002 lines from both versions, instead of leaving conflict
1003 markers. This tends to leave the added lines in the
1004 resulting file in random order and the user should
1005 verify the result. Do not use this if you do not
1006 understand the implications.
1007 </p>
1008 </dd>
1009 </dl></div>
1010 <h4 id="_defining_a_custom_merge_driver">Defining a custom merge driver</h4>
1011 <div class="para"><p>The definition of a merge driver is done in the <tt>.git/config</tt>
1012 file, not in the <tt>gitattributes</tt> file, so strictly speaking this
1013 manual page is a wrong place to talk about it. However&#8230;</p></div>
1014 <div class="para"><p>To define a custom merge driver <tt>filfre</tt>, add a section to your
1015 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
1016 <div class="listingblock">
1017 <div class="content">
1018 <pre><tt>[merge "filfre"]
1019 name = feel-free merge driver
1020 driver = filfre %O %A %B
1021 recursive = binary</tt></pre>
1022 </div></div>
1023 <div class="para"><p>The <tt>merge.*.name</tt> variable gives the driver a human-readable
1024 name.</p></div>
1025 <div class="para"><p>The <tt>merge.*.driver</tt> variable's value is used to construct a
1026 command to run to merge ancestor's version (<tt>%O</tt>), current
1027 version (<tt>%A</tt>) and the other branches' version (<tt>%B</tt>). These
1028 three tokens are replaced with the names of temporary files that
1029 hold the contents of these versions when the command line is
1030 built. Additionally, %L will be replaced with the conflict marker
1031 size (see below).</p></div>
1032 <div class="para"><p>The merge driver is expected to leave the result of the merge in
1033 the file named with <tt>%A</tt> by overwriting it, and exit with zero
1034 status if it managed to merge them cleanly, or non-zero if there
1035 were conflicts.</p></div>
1036 <div class="para"><p>The <tt>merge.*.recursive</tt> variable specifies what other merge
1037 driver to use when the merge driver is called for an internal
1038 merge between common ancestors, when there are more than one.
1039 When left unspecified, the driver itself is used for both
1040 internal merge and the final merge.</p></div>
1041 <h4 id="_tt_conflict_marker_size_tt"><tt>conflict-marker-size</tt></h4>
1042 <div class="para"><p>This attribute controls the length of conflict markers left in
1043 the work tree file during a conflicted merge. Only setting to
1044 the value to a positive integer has any meaningful effect.</p></div>
1045 <div class="para"><p>For example, this line in <tt>.gitattributes</tt> can be used to tell the merge
1046 machinery to leave much longer (instead of the usual 7-character-long)
1047 conflict markers when merging the file <tt>Documentation/git-merge.txt</tt>
1048 results in a conflict.</p></div>
1049 <div class="listingblock">
1050 <div class="content">
1051 <pre><tt>Documentation/git-merge.txt conflict-marker-size=32</tt></pre>
1052 </div></div>
1053 <h3 id="_checking_whitespace_errors">Checking whitespace errors</h3><div style="clear:left"></div>
1054 <h4 id="_tt_whitespace_tt"><tt>whitespace</tt></h4>
1055 <div class="para"><p>The <tt>core.whitespace</tt> configuration variable allows you to define what
1056 <em>diff</em> and <em>apply</em> should consider whitespace errors for all paths in
1057 the project (See <a href="git-config.html">git-config(1)</a>). This attribute gives you finer
1058 control per path.</p></div>
1059 <div class="vlist"><dl>
1060 <dt>
1062 </dt>
1063 <dd>
1065 Notice all types of potential whitespace errors known to git.
1066 </p>
1067 </dd>
1068 <dt>
1069 Unset
1070 </dt>
1071 <dd>
1073 Do not notice anything as error.
1074 </p>
1075 </dd>
1076 <dt>
1077 Unspecified
1078 </dt>
1079 <dd>
1081 Use the value of <tt>core.whitespace</tt> configuration variable to
1082 decide what to notice as error.
1083 </p>
1084 </dd>
1085 <dt>
1086 String
1087 </dt>
1088 <dd>
1090 Specify a comma separate list of common whitespace problems to
1091 notice in the same format as <tt>core.whitespace</tt> configuration
1092 variable.
1093 </p>
1094 </dd>
1095 </dl></div>
1096 <h3 id="_creating_an_archive">Creating an archive</h3><div style="clear:left"></div>
1097 <h4 id="_tt_export_ignore_tt"><tt>export-ignore</tt></h4>
1098 <div class="para"><p>Files and directories with the attribute <tt>export-ignore</tt> won't be added to
1099 archive files.</p></div>
1100 <h4 id="_tt_export_subst_tt"><tt>export-subst</tt></h4>
1101 <div class="para"><p>If the attribute <tt>export-subst</tt> is set for a file then git will expand
1102 several placeholders when adding this file to an archive. The
1103 expansion depends on the availability of a commit ID, i.e., if
1104 <a href="git-archive.html">git-archive(1)</a> has been given a tree instead of a commit or a
1105 tag then no replacement will be done. The placeholders are the same
1106 as those for the option <tt>--pretty=format:</tt> of <a href="git-log.html">git-log(1)</a>,
1107 except that they need to be wrapped like this: <tt>$Format:PLACEHOLDERS$</tt>
1108 in the file. E.g. the string <tt>$Format:%H$</tt> will be replaced by the
1109 commit hash.</p></div>
1110 <h3 id="_packing_objects">Packing objects</h3><div style="clear:left"></div>
1111 <h4 id="_tt_delta_tt"><tt>delta</tt></h4>
1112 <div class="para"><p>Delta compression will not be attempted for blobs for paths with the
1113 attribute <tt>delta</tt> set to false.</p></div>
1114 <h3 id="_viewing_files_in_gui_tools">Viewing files in GUI tools</h3><div style="clear:left"></div>
1115 <h4 id="_tt_encoding_tt"><tt>encoding</tt></h4>
1116 <div class="para"><p>The value of this attribute specifies the character encoding that should
1117 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
1118 display the contents of the relevant file. Note that due to performance
1119 considerations <a href="gitk.html">gitk(1)</a> does not use this attribute unless you
1120 manually enable per-file encodings in its options.</p></div>
1121 <div class="para"><p>If this attribute is not set or has an invalid value, the value of the
1122 <tt>gui.encoding</tt> configuration variable is used instead
1123 (See <a href="git-config.html">git-config(1)</a>).</p></div>
1124 </div>
1125 <h2 id="_using_attribute_macros">USING ATTRIBUTE MACROS</h2>
1126 <div class="sectionbody">
1127 <div class="para"><p>You do not want any end-of-line conversions applied to, nor textual diffs
1128 produced for, any binary file you track. You would need to specify e.g.</p></div>
1129 <div class="listingblock">
1130 <div class="content">
1131 <pre><tt>*.jpg -text -diff</tt></pre>
1132 </div></div>
1133 <div class="para"><p>but that may become cumbersome, when you have many attributes. Using
1134 attribute macros, you can specify groups of attributes set or unset at
1135 the same time. The system knows a built-in attribute macro, <tt>binary</tt>:</p></div>
1136 <div class="listingblock">
1137 <div class="content">
1138 <pre><tt>*.jpg binary</tt></pre>
1139 </div></div>
1140 <div class="para"><p>which is equivalent to the above. Note that the attribute macros can only
1141 be "Set" (see the above example that sets "binary" macro as if it were an
1142 ordinary attribute --- setting it in turn unsets "text" and "diff").</p></div>
1143 </div>
1144 <h2 id="_defining_attribute_macros">DEFINING ATTRIBUTE MACROS</h2>
1145 <div class="sectionbody">
1146 <div class="para"><p>Custom attribute macros can be defined only in the <tt>.gitattributes</tt> file
1147 at the toplevel (i.e. not in any subdirectory). The built-in attribute
1148 macro "binary" is equivalent to:</p></div>
1149 <div class="listingblock">
1150 <div class="content">
1151 <pre><tt>[attr]binary -diff -text</tt></pre>
1152 </div></div>
1153 </div>
1154 <h2 id="_example">EXAMPLE</h2>
1155 <div class="sectionbody">
1156 <div class="para"><p>If you have these three <tt>gitattributes</tt> file:</p></div>
1157 <div class="listingblock">
1158 <div class="content">
1159 <pre><tt>(in $GIT_DIR/info/attributes)
1161 a* foo !bar -baz
1163 (in .gitattributes)
1164 abc foo bar baz
1166 (in t/.gitattributes)
1167 ab* merge=filfre
1168 abc -foo -bar
1169 *.c frotz</tt></pre>
1170 </div></div>
1171 <div class="para"><p>the attributes given to path <tt>t/abc</tt> are computed as follows:</p></div>
1172 <div class="olist"><ol>
1173 <li>
1175 By examining <tt>t/.gitattributes</tt> (which is in the same
1176 directory as the path in question), git finds that the first
1177 line matches. <tt>merge</tt> attribute is set. It also finds that
1178 the second line matches, and attributes <tt>foo</tt> and <tt>bar</tt>
1179 are unset.
1180 </p>
1181 </li>
1182 <li>
1184 Then it examines <tt>.gitattributes</tt> (which is in the parent
1185 directory), and finds that the first line matches, but
1186 <tt>t/.gitattributes</tt> file already decided how <tt>merge</tt>, <tt>foo</tt>
1187 and <tt>bar</tt> attributes should be given to this path, so it
1188 leaves <tt>foo</tt> and <tt>bar</tt> unset. Attribute <tt>baz</tt> is set.
1189 </p>
1190 </li>
1191 <li>
1193 Finally it examines <tt>$GIT_DIR/info/attributes</tt>. This file
1194 is used to override the in-tree settings. The first line is
1195 a match, and <tt>foo</tt> is set, <tt>bar</tt> is reverted to unspecified
1196 state, and <tt>baz</tt> is unset.
1197 </p>
1198 </li>
1199 </ol></div>
1200 <div class="para"><p>As the result, the attributes assignment to <tt>t/abc</tt> becomes:</p></div>
1201 <div class="listingblock">
1202 <div class="content">
1203 <pre><tt>foo set to true
1204 bar unspecified
1205 baz set to false
1206 merge set to string value "filfre"
1207 frotz unspecified</tt></pre>
1208 </div></div>
1209 </div>
1210 <h2 id="_git">GIT</h2>
1211 <div class="sectionbody">
1212 <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1213 </div>
1214 <div id="footer">
1215 <div id="footer-text">
1216 Last updated 2010-09-03 21:30:36 UTC
1217 </div>
1218 </div>
1219 </body>
1220 </html>