Autogenerated HTML docs for v1.6.5
[git/jnareb-git.git] / gitattributes.html
blob87882ce8e46efdaf72c2909d0282b03b533278e0
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 <h4 id="_interaction_between_checkin_checkout_attributes">Interaction between checkin/checkout attributes</h4>
526 <div class="para"><p>In the check-in codepath, the worktree file is first converted
527 with <tt>filter</tt> driver (if specified and corresponding driver
528 defined), then the result is processed with <tt>ident</tt> (if
529 specified), and then finally with <tt>crlf</tt> (again, if specified
530 and applicable).</p></div>
531 <div class="para"><p>In the check-out codepath, the blob content is first converted
532 with <tt>crlf</tt>, and then <tt>ident</tt> and fed to <tt>filter</tt>.</p></div>
533 <h3 id="_generating_diff_text">Generating diff text</h3><div style="clear:left"></div>
534 <h4 id="_tt_diff_tt"><tt>diff</tt></h4>
535 <div class="para"><p>The attribute <tt>diff</tt> affects how <em>git</em> generates diffs for particular
536 files. It can tell git whether to generate a textual patch for the path
537 or to treat the path as a binary file. It can also affect what line is
538 shown on the hunk header <tt>@@ -k,l +n,m @@</tt> line, tell git to use an
539 external command to generate the diff, or ask git to convert binary
540 files to a text format before generating the diff.</p></div>
541 <div class="vlist"><dl>
542 <dt>
544 </dt>
545 <dd>
547 A path to which the <tt>diff</tt> attribute is set is treated
548 as text, even when they contain byte values that
549 normally never appear in text files, such as NUL.
550 </p>
551 </dd>
552 <dt>
553 Unset
554 </dt>
555 <dd>
557 A path to which the <tt>diff</tt> attribute is unset will
558 generate <tt>Binary files differ</tt> (or a binary patch, if
559 binary patches are enabled).
560 </p>
561 </dd>
562 <dt>
563 Unspecified
564 </dt>
565 <dd>
567 A path to which the <tt>diff</tt> attribute is unspecified
568 first gets its contents inspected, and if it looks like
569 text, it is treated as text. Otherwise it would
570 generate <tt>Binary files differ</tt>.
571 </p>
572 </dd>
573 <dt>
574 String
575 </dt>
576 <dd>
578 Diff is shown using the specified diff driver. Each driver may
579 specify one or more options, as described in the following
580 section. The options for the diff driver "foo" are defined
581 by the configuration variables in the "diff.foo" section of the
582 git config file.
583 </p>
584 </dd>
585 </dl></div>
586 <h4 id="_defining_an_external_diff_driver">Defining an external diff driver</h4>
587 <div class="para"><p>The definition of a diff driver is done in <tt>gitconfig</tt>, not
588 <tt>gitattributes</tt> file, so strictly speaking this manual page is a
589 wrong place to talk about it. However&#8230;</p></div>
590 <div class="para"><p>To define an external diff driver <tt>jcdiff</tt>, add a section to your
591 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
592 <div class="listingblock">
593 <div class="content">
594 <pre><tt>[diff "jcdiff"]
595 command = j-c-diff</tt></pre>
596 </div></div>
597 <div class="para"><p>When git needs to show you a diff for the path with <tt>diff</tt>
598 attribute set to <tt>jcdiff</tt>, it calls the command you specified
599 with the above configuration, i.e. <tt>j-c-diff</tt>, with 7
600 parameters, just like <tt>GIT_EXTERNAL_DIFF</tt> program is called.
601 See <a href="git.html">git(1)</a> for details.</p></div>
602 <h4 id="_defining_a_custom_hunk_header">Defining a custom hunk-header</h4>
603 <div class="para"><p>Each group of changes (called a "hunk") in the textual diff output
604 is prefixed with a line of the form:</p></div>
605 <div class="literalblock">
606 <div class="content">
607 <pre><tt>@@ -k,l +n,m @@ TEXT</tt></pre>
608 </div></div>
609 <div class="para"><p>This is called a <em>hunk header</em>. The "TEXT" portion is by default a line
610 that begins with an alphabet, an underscore or a dollar sign; this
611 matches what GNU <em>diff -p</em> output uses. This default selection however
612 is not suited for some contents, and you can use a customized pattern
613 to make a selection.</p></div>
614 <div class="para"><p>First, in .gitattributes, you would assign the <tt>diff</tt> attribute
615 for paths.</p></div>
616 <div class="listingblock">
617 <div class="content">
618 <pre><tt>*.tex diff=tex</tt></pre>
619 </div></div>
620 <div class="para"><p>Then, you would define a "diff.tex.xfuncname" configuration to
621 specify a regular expression that matches a line that you would
622 want to appear as the hunk header "TEXT". Add a section to your
623 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
624 <div class="listingblock">
625 <div class="content">
626 <pre><tt>[diff "tex"]
627 xfuncname = "^(\\\\(sub)*section\\{.*)$"</tt></pre>
628 </div></div>
629 <div class="para"><p>Note. A single level of backslashes are eaten by the
630 configuration file parser, so you would need to double the
631 backslashes; the pattern above picks a line that begins with a
632 backslash, and zero or more occurrences of <tt>sub</tt> followed by
633 <tt>section</tt> followed by open brace, to the end of line.</p></div>
634 <div class="para"><p>There are a few built-in patterns to make this easier, and <tt>tex</tt>
635 is one of them, so you do not have to write the above in your
636 configuration file (you still need to enable this with the
637 attribute mechanism, via <tt>.gitattributes</tt>). The following built in
638 patterns are available:</p></div>
639 <div class="ilist"><ul>
640 <li>
642 <tt>bibtex</tt> suitable for files with BibTeX coded references.
643 </p>
644 </li>
645 <li>
647 <tt>cpp</tt> suitable for source code in the C and C++ languages.
648 </p>
649 </li>
650 <li>
652 <tt>html</tt> suitable for HTML/XHTML documents.
653 </p>
654 </li>
655 <li>
657 <tt>java</tt> suitable for source code in the Java language.
658 </p>
659 </li>
660 <li>
662 <tt>objc</tt> suitable for source code in the Objective-C language.
663 </p>
664 </li>
665 <li>
667 <tt>pascal</tt> suitable for source code in the Pascal/Delphi language.
668 </p>
669 </li>
670 <li>
672 <tt>php</tt> suitable for source code in the PHP language.
673 </p>
674 </li>
675 <li>
677 <tt>python</tt> suitable for source code in the Python language.
678 </p>
679 </li>
680 <li>
682 <tt>ruby</tt> suitable for source code in the Ruby language.
683 </p>
684 </li>
685 <li>
687 <tt>tex</tt> suitable for source code for LaTeX documents.
688 </p>
689 </li>
690 </ul></div>
691 <h4 id="_customizing_word_diff">Customizing word diff</h4>
692 <div class="para"><p>You can customize the rules that <tt>git diff --color-words</tt> uses to
693 split words in a line, by specifying an appropriate regular expression
694 in the "diff.*.wordRegex" configuration variable. For example, in TeX
695 a backslash followed by a sequence of letters forms a command, but
696 several such commands can be run together without intervening
697 whitespace. To separate them, use a regular expression in your
698 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
699 <div class="listingblock">
700 <div class="content">
701 <pre><tt>[diff "tex"]
702 wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"</tt></pre>
703 </div></div>
704 <div class="para"><p>A built-in pattern is provided for all languages listed in the
705 previous section.</p></div>
706 <h4 id="_performing_text_diffs_of_binary_files">Performing text diffs of binary files</h4>
707 <div class="para"><p>Sometimes it is desirable to see the diff of a text-converted
708 version of some binary files. For example, a word processor
709 document can be converted to an ASCII text representation, and
710 the diff of the text shown. Even though this conversion loses
711 some information, the resulting diff is useful for human
712 viewing (but cannot be applied directly).</p></div>
713 <div class="para"><p>The <tt>textconv</tt> config option is used to define a program for
714 performing such a conversion. The program should take a single
715 argument, the name of a file to convert, and produce the
716 resulting text on stdout.</p></div>
717 <div class="para"><p>For example, to show the diff of the exif information of a
718 file instead of the binary information (assuming you have the
719 exif tool installed), add the following section to your
720 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file):</p></div>
721 <div class="listingblock">
722 <div class="content">
723 <pre><tt>[diff "jpg"]
724 textconv = exif</tt></pre>
725 </div></div>
726 <div class="admonitionblock">
727 <table><tr>
728 <td class="icon">
729 <div class="title">Note</div>
730 </td>
731 <td class="content">The text conversion is generally a one-way conversion;
732 in this example, we lose the actual image contents and focus
733 just on the text data. This means that diffs generated by
734 textconv are _not_ suitable for applying. For this reason,
735 only <tt>git diff</tt> and the <tt>git log</tt> family of commands (i.e.,
736 log, whatchanged, show) will perform text conversion. <tt>git
737 format-patch</tt> will never generate this output. If you want to
738 send somebody a text-converted diff of a binary file (e.g.,
739 because it quickly conveys the changes you have made), you
740 should generate it separately and send it as a comment _in
741 addition to_ the usual binary diff that you might send.</td>
742 </tr></table>
743 </div>
744 <h3 id="_performing_a_three_way_merge">Performing a three-way merge</h3><div style="clear:left"></div>
745 <h4 id="_tt_merge_tt"><tt>merge</tt></h4>
746 <div class="para"><p>The attribute <tt>merge</tt> affects how three versions of a file is
747 merged when a file-level merge is necessary during <tt>git merge</tt>,
748 and other commands such as <tt>git revert</tt> and <tt>git cherry-pick</tt>.</p></div>
749 <div class="vlist"><dl>
750 <dt>
752 </dt>
753 <dd>
755 Built-in 3-way merge driver is used to merge the
756 contents in a way similar to <em>merge</em> command of <tt>RCS</tt>
757 suite. This is suitable for ordinary text files.
758 </p>
759 </dd>
760 <dt>
761 Unset
762 </dt>
763 <dd>
765 Take the version from the current branch as the
766 tentative merge result, and declare that the merge has
767 conflicts. This is suitable for binary files that does
768 not have a well-defined merge semantics.
769 </p>
770 </dd>
771 <dt>
772 Unspecified
773 </dt>
774 <dd>
776 By default, this uses the same built-in 3-way merge
777 driver as is the case the <tt>merge</tt> attribute is set.
778 However, <tt>merge.default</tt> configuration variable can name
779 different merge driver to be used for paths to which the
780 <tt>merge</tt> attribute is unspecified.
781 </p>
782 </dd>
783 <dt>
784 String
785 </dt>
786 <dd>
788 3-way merge is performed using the specified custom
789 merge driver. The built-in 3-way merge driver can be
790 explicitly specified by asking for "text" driver; the
791 built-in "take the current branch" driver can be
792 requested with "binary".
793 </p>
794 </dd>
795 </dl></div>
796 <h4 id="_built_in_merge_drivers">Built-in merge drivers</h4>
797 <div class="para"><p>There are a few built-in low-level merge drivers defined that
798 can be asked for via the <tt>merge</tt> attribute.</p></div>
799 <div class="vlist"><dl>
800 <dt>
801 text
802 </dt>
803 <dd>
805 Usual 3-way file level merge for text files. Conflicted
806 regions are marked with conflict markers <tt>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</tt>,
807 <tt>=======</tt> and <tt>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</tt>. The version from your branch
808 appears before the <tt>=======</tt> marker, and the version
809 from the merged branch appears after the <tt>=======</tt>
810 marker.
811 </p>
812 </dd>
813 <dt>
814 binary
815 </dt>
816 <dd>
818 Keep the version from your branch in the work tree, but
819 leave the path in the conflicted state for the user to
820 sort out.
821 </p>
822 </dd>
823 <dt>
824 union
825 </dt>
826 <dd>
828 Run 3-way file level merge for text files, but take
829 lines from both versions, instead of leaving conflict
830 markers. This tends to leave the added lines in the
831 resulting file in random order and the user should
832 verify the result. Do not use this if you do not
833 understand the implications.
834 </p>
835 </dd>
836 </dl></div>
837 <h4 id="_defining_a_custom_merge_driver">Defining a custom merge driver</h4>
838 <div class="para"><p>The definition of a merge driver is done in the <tt>.git/config</tt>
839 file, not in the <tt>gitattributes</tt> file, so strictly speaking this
840 manual page is a wrong place to talk about it. However&#8230;</p></div>
841 <div class="para"><p>To define a custom merge driver <tt>filfre</tt>, add a section to your
842 <tt>$GIT_DIR/config</tt> file (or <tt>$HOME/.gitconfig</tt> file) like this:</p></div>
843 <div class="listingblock">
844 <div class="content">
845 <pre><tt>[merge "filfre"]
846 name = feel-free merge driver
847 driver = filfre %O %A %B
848 recursive = binary</tt></pre>
849 </div></div>
850 <div class="para"><p>The <tt>merge.*.name</tt> variable gives the driver a human-readable
851 name.</p></div>
852 <div class="para"><p>The <tt>merge.*.driver</tt> variable's value is used to construct a
853 command to run to merge ancestor's version (<tt>%O</tt>), current
854 version (<tt>%A</tt>) and the other branches' version (<tt>%B</tt>). These
855 three tokens are replaced with the names of temporary files that
856 hold the contents of these versions when the command line is
857 built.</p></div>
858 <div class="para"><p>The merge driver is expected to leave the result of the merge in
859 the file named with <tt>%A</tt> by overwriting it, and exit with zero
860 status if it managed to merge them cleanly, or non-zero if there
861 were conflicts.</p></div>
862 <div class="para"><p>The <tt>merge.*.recursive</tt> variable specifies what other merge
863 driver to use when the merge driver is called for an internal
864 merge between common ancestors, when there are more than one.
865 When left unspecified, the driver itself is used for both
866 internal merge and the final merge.</p></div>
867 <h3 id="_checking_whitespace_errors">Checking whitespace errors</h3><div style="clear:left"></div>
868 <h4 id="_tt_whitespace_tt"><tt>whitespace</tt></h4>
869 <div class="para"><p>The <tt>core.whitespace</tt> configuration variable allows you to define what
870 <em>diff</em> and <em>apply</em> should consider whitespace errors for all paths in
871 the project (See <a href="git-config.html">git-config(1)</a>). This attribute gives you finer
872 control per path.</p></div>
873 <div class="vlist"><dl>
874 <dt>
876 </dt>
877 <dd>
879 Notice all types of potential whitespace errors known to git.
880 </p>
881 </dd>
882 <dt>
883 Unset
884 </dt>
885 <dd>
887 Do not notice anything as error.
888 </p>
889 </dd>
890 <dt>
891 Unspecified
892 </dt>
893 <dd>
895 Use the value of <tt>core.whitespace</tt> configuration variable to
896 decide what to notice as error.
897 </p>
898 </dd>
899 <dt>
900 String
901 </dt>
902 <dd>
904 Specify a comma separate list of common whitespace problems to
905 notice in the same format as <tt>core.whitespace</tt> configuration
906 variable.
907 </p>
908 </dd>
909 </dl></div>
910 <h3 id="_creating_an_archive">Creating an archive</h3><div style="clear:left"></div>
911 <h4 id="_tt_export_ignore_tt"><tt>export-ignore</tt></h4>
912 <div class="para"><p>Files and directories with the attribute <tt>export-ignore</tt> won't be added to
913 archive files.</p></div>
914 <h4 id="_tt_export_subst_tt"><tt>export-subst</tt></h4>
915 <div class="para"><p>If the attribute <tt>export-subst</tt> is set for a file then git will expand
916 several placeholders when adding this file to an archive. The
917 expansion depends on the availability of a commit ID, i.e., if
918 <a href="git-archive.html">git-archive(1)</a> has been given a tree instead of a commit or a
919 tag then no replacement will be done. The placeholders are the same
920 as those for the option <tt>--pretty=format:</tt> of <a href="git-log.html">git-log(1)</a>,
921 except that they need to be wrapped like this: <tt>$Format:PLACEHOLDERS$</tt>
922 in the file. E.g. the string <tt>$Format:%H$</tt> will be replaced by the
923 commit hash.</p></div>
924 <h3 id="_viewing_files_in_gui_tools">Viewing files in GUI tools</h3><div style="clear:left"></div>
925 <h4 id="_tt_encoding_tt"><tt>encoding</tt></h4>
926 <div class="para"><p>The value of this attribute specifies the character encoding that should
927 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
928 display the contents of the relevant file. Note that due to performance
929 considerations <a href="gitk.html">gitk(1)</a> does not use this attribute unless you
930 manually enable per-file encodings in its options.</p></div>
931 <div class="para"><p>If this attribute is not set or has an invalid value, the value of the
932 <tt>gui.encoding</tt> configuration variable is used instead
933 (See <a href="git-config.html">git-config(1)</a>).</p></div>
934 </div>
935 <h2 id="_using_attribute_macros">USING ATTRIBUTE MACROS</h2>
936 <div class="sectionbody">
937 <div class="para"><p>You do not want any end-of-line conversions applied to, nor textual diffs
938 produced for, any binary file you track. You would need to specify e.g.</p></div>
939 <div class="listingblock">
940 <div class="content">
941 <pre><tt>*.jpg -crlf -diff</tt></pre>
942 </div></div>
943 <div class="para"><p>but that may become cumbersome, when you have many attributes. Using
944 attribute macros, you can specify groups of attributes set or unset at
945 the same time. The system knows a built-in attribute macro, <tt>binary</tt>:</p></div>
946 <div class="listingblock">
947 <div class="content">
948 <pre><tt>*.jpg binary</tt></pre>
949 </div></div>
950 <div class="para"><p>which is equivalent to the above. Note that the attribute macros can only
951 be "Set" (see the above example that sets "binary" macro as if it were an
952 ordinary attribute --- setting it in turn unsets "crlf" and "diff").</p></div>
953 </div>
954 <h2 id="_defining_attribute_macros">DEFINING ATTRIBUTE MACROS</h2>
955 <div class="sectionbody">
956 <div class="para"><p>Custom attribute macros can be defined only in the <tt>.gitattributes</tt> file
957 at the toplevel (i.e. not in any subdirectory). The built-in attribute
958 macro "binary" is equivalent to:</p></div>
959 <div class="listingblock">
960 <div class="content">
961 <pre><tt>[attr]binary -diff -crlf</tt></pre>
962 </div></div>
963 </div>
964 <h2 id="_example">EXAMPLE</h2>
965 <div class="sectionbody">
966 <div class="para"><p>If you have these three <tt>gitattributes</tt> file:</p></div>
967 <div class="listingblock">
968 <div class="content">
969 <pre><tt>(in $GIT_DIR/info/attributes)
971 a* foo !bar -baz
973 (in .gitattributes)
974 abc foo bar baz
976 (in t/.gitattributes)
977 ab* merge=filfre
978 abc -foo -bar
979 *.c frotz</tt></pre>
980 </div></div>
981 <div class="para"><p>the attributes given to path <tt>t/abc</tt> are computed as follows:</p></div>
982 <div class="olist"><ol>
983 <li>
985 By examining <tt>t/.gitattributes</tt> (which is in the same
986 directory as the path in question), git finds that the first
987 line matches. <tt>merge</tt> attribute is set. It also finds that
988 the second line matches, and attributes <tt>foo</tt> and <tt>bar</tt>
989 are unset.
990 </p>
991 </li>
992 <li>
994 Then it examines <tt>.gitattributes</tt> (which is in the parent
995 directory), and finds that the first line matches, but
996 <tt>t/.gitattributes</tt> file already decided how <tt>merge</tt>, <tt>foo</tt>
997 and <tt>bar</tt> attributes should be given to this path, so it
998 leaves <tt>foo</tt> and <tt>bar</tt> unset. Attribute <tt>baz</tt> is set.
999 </p>
1000 </li>
1001 <li>
1003 Finally it examines <tt>$GIT_DIR/info/attributes</tt>. This file
1004 is used to override the in-tree settings. The first line is
1005 a match, and <tt>foo</tt> is set, <tt>bar</tt> is reverted to unspecified
1006 state, and <tt>baz</tt> is unset.
1007 </p>
1008 </li>
1009 </ol></div>
1010 <div class="para"><p>As the result, the attributes assignment to <tt>t/abc</tt> becomes:</p></div>
1011 <div class="listingblock">
1012 <div class="content">
1013 <pre><tt>foo set to true
1014 bar unspecified
1015 baz set to false
1016 merge set to string value "filfre"
1017 frotz unspecified</tt></pre>
1018 </div></div>
1019 </div>
1020 <h2 id="_git">GIT</h2>
1021 <div class="sectionbody">
1022 <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1023 </div>
1024 <div id="footer">
1025 <div id="footer-text">
1026 Last updated 2009-08-13 01:22:28 UTC
1027 </div>
1028 </div>
1029 </body>
1030 </html>