Autogenerated HTML docs for v2.45.1-204-gd8ab1
[git-htmldocs.git] / gitattributes.html
blob31f5aaf27d611794a8b77c9d101d1752e5db5fee
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
5 <head>
6 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
7 <meta name="generator" content="AsciiDoc 10.2.0" />
8 <title>gitattributes(5)</title>
9 <style type="text/css">
10 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
12 /* Default font. */
13 body {
14 font-family: Georgia,serif;
17 /* Title font. */
18 h1, h2, h3, h4, h5, h6,
19 div.title, caption.title,
20 thead, p.table.header,
21 #toctitle,
22 #author, #revnumber, #revdate, #revremark,
23 #footer {
24 font-family: Arial,Helvetica,sans-serif;
27 body {
28 margin: 1em 5% 1em 5%;
31 a {
32 color: blue;
33 text-decoration: underline;
35 a:visited {
36 color: fuchsia;
39 em {
40 font-style: italic;
41 color: navy;
44 strong {
45 font-weight: bold;
46 color: #083194;
49 h1, h2, h3, h4, h5, h6 {
50 color: #527bbd;
51 margin-top: 1.2em;
52 margin-bottom: 0.5em;
53 line-height: 1.3;
56 h1, h2, h3 {
57 border-bottom: 2px solid silver;
59 h2 {
60 padding-top: 0.5em;
62 h3 {
63 float: left;
65 h3 + * {
66 clear: left;
68 h5 {
69 font-size: 1.0em;
72 div.sectionbody {
73 margin-left: 0;
76 hr {
77 border: 1px solid silver;
80 p {
81 margin-top: 0.5em;
82 margin-bottom: 0.5em;
85 ul, ol, li > p {
86 margin-top: 0;
88 ul > li { color: #aaa; }
89 ul > li > * { color: black; }
91 .monospaced, code, pre {
92 font-family: "Courier New", Courier, monospace;
93 font-size: inherit;
94 color: navy;
95 padding: 0;
96 margin: 0;
98 pre {
99 white-space: pre-wrap;
102 #author {
103 color: #527bbd;
104 font-weight: bold;
105 font-size: 1.1em;
107 #email {
109 #revnumber, #revdate, #revremark {
112 #footer {
113 font-size: small;
114 border-top: 2px solid silver;
115 padding-top: 0.5em;
116 margin-top: 4.0em;
118 #footer-text {
119 float: left;
120 padding-bottom: 0.5em;
122 #footer-badges {
123 float: right;
124 padding-bottom: 0.5em;
127 #preamble {
128 margin-top: 1.5em;
129 margin-bottom: 1.5em;
131 div.imageblock, div.exampleblock, div.verseblock,
132 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
133 div.admonitionblock {
134 margin-top: 1.0em;
135 margin-bottom: 1.5em;
137 div.admonitionblock {
138 margin-top: 2.0em;
139 margin-bottom: 2.0em;
140 margin-right: 10%;
141 color: #606060;
144 div.content { /* Block element content. */
145 padding: 0;
148 /* Block element titles. */
149 div.title, caption.title {
150 color: #527bbd;
151 font-weight: bold;
152 text-align: left;
153 margin-top: 1.0em;
154 margin-bottom: 0.5em;
156 div.title + * {
157 margin-top: 0;
160 td div.title:first-child {
161 margin-top: 0.0em;
163 div.content div.title:first-child {
164 margin-top: 0.0em;
166 div.content + div.title {
167 margin-top: 0.0em;
170 div.sidebarblock > div.content {
171 background: #ffffee;
172 border: 1px solid #dddddd;
173 border-left: 4px solid #f0f0f0;
174 padding: 0.5em;
177 div.listingblock > div.content {
178 border: 1px solid #dddddd;
179 border-left: 5px solid #f0f0f0;
180 background: #f8f8f8;
181 padding: 0.5em;
184 div.quoteblock, div.verseblock {
185 padding-left: 1.0em;
186 margin-left: 1.0em;
187 margin-right: 10%;
188 border-left: 5px solid #f0f0f0;
189 color: #888;
192 div.quoteblock > div.attribution {
193 padding-top: 0.5em;
194 text-align: right;
197 div.verseblock > pre.content {
198 font-family: inherit;
199 font-size: inherit;
201 div.verseblock > div.attribution {
202 padding-top: 0.75em;
203 text-align: left;
205 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
206 div.verseblock + div.attribution {
207 text-align: left;
210 div.admonitionblock .icon {
211 vertical-align: top;
212 font-size: 1.1em;
213 font-weight: bold;
214 text-decoration: underline;
215 color: #527bbd;
216 padding-right: 0.5em;
218 div.admonitionblock td.content {
219 padding-left: 0.5em;
220 border-left: 3px solid #dddddd;
223 div.exampleblock > div.content {
224 border-left: 3px solid #dddddd;
225 padding-left: 0.5em;
228 div.imageblock div.content { padding-left: 0; }
229 span.image img { border-style: none; vertical-align: text-bottom; }
230 a.image:visited { color: white; }
232 dl {
233 margin-top: 0.8em;
234 margin-bottom: 0.8em;
236 dt {
237 margin-top: 0.5em;
238 margin-bottom: 0;
239 font-style: normal;
240 color: navy;
242 dd > *:first-child {
243 margin-top: 0.1em;
246 ul, ol {
247 list-style-position: outside;
249 ol.arabic {
250 list-style-type: decimal;
252 ol.loweralpha {
253 list-style-type: lower-alpha;
255 ol.upperalpha {
256 list-style-type: upper-alpha;
258 ol.lowerroman {
259 list-style-type: lower-roman;
261 ol.upperroman {
262 list-style-type: upper-roman;
265 div.compact ul, div.compact ol,
266 div.compact p, div.compact p,
267 div.compact div, div.compact div {
268 margin-top: 0.1em;
269 margin-bottom: 0.1em;
272 tfoot {
273 font-weight: bold;
275 td > div.verse {
276 white-space: pre;
279 div.hdlist {
280 margin-top: 0.8em;
281 margin-bottom: 0.8em;
283 div.hdlist tr {
284 padding-bottom: 15px;
286 dt.hdlist1.strong, td.hdlist1.strong {
287 font-weight: bold;
289 td.hdlist1 {
290 vertical-align: top;
291 font-style: normal;
292 padding-right: 0.8em;
293 color: navy;
295 td.hdlist2 {
296 vertical-align: top;
298 div.hdlist.compact tr {
299 margin: 0;
300 padding-bottom: 0;
303 .comment {
304 background: yellow;
307 .footnote, .footnoteref {
308 font-size: 0.8em;
311 span.footnote, span.footnoteref {
312 vertical-align: super;
315 #footnotes {
316 margin: 20px 0 20px 0;
317 padding: 7px 0 0 0;
320 #footnotes div.footnote {
321 margin: 0 0 5px 0;
324 #footnotes hr {
325 border: none;
326 border-top: 1px solid silver;
327 height: 1px;
328 text-align: left;
329 margin-left: 0;
330 width: 20%;
331 min-width: 100px;
334 div.colist td {
335 padding-right: 0.5em;
336 padding-bottom: 0.3em;
337 vertical-align: top;
339 div.colist td img {
340 margin-top: 0.3em;
343 @media print {
344 #footer-badges { display: none; }
347 #toc {
348 margin-bottom: 2.5em;
351 #toctitle {
352 color: #527bbd;
353 font-size: 1.1em;
354 font-weight: bold;
355 margin-top: 1.0em;
356 margin-bottom: 0.1em;
359 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
360 margin-top: 0;
361 margin-bottom: 0;
363 div.toclevel2 {
364 margin-left: 2em;
365 font-size: 0.9em;
367 div.toclevel3 {
368 margin-left: 4em;
369 font-size: 0.9em;
371 div.toclevel4 {
372 margin-left: 6em;
373 font-size: 0.9em;
376 span.aqua { color: aqua; }
377 span.black { color: black; }
378 span.blue { color: blue; }
379 span.fuchsia { color: fuchsia; }
380 span.gray { color: gray; }
381 span.green { color: green; }
382 span.lime { color: lime; }
383 span.maroon { color: maroon; }
384 span.navy { color: navy; }
385 span.olive { color: olive; }
386 span.purple { color: purple; }
387 span.red { color: red; }
388 span.silver { color: silver; }
389 span.teal { color: teal; }
390 span.white { color: white; }
391 span.yellow { color: yellow; }
393 span.aqua-background { background: aqua; }
394 span.black-background { background: black; }
395 span.blue-background { background: blue; }
396 span.fuchsia-background { background: fuchsia; }
397 span.gray-background { background: gray; }
398 span.green-background { background: green; }
399 span.lime-background { background: lime; }
400 span.maroon-background { background: maroon; }
401 span.navy-background { background: navy; }
402 span.olive-background { background: olive; }
403 span.purple-background { background: purple; }
404 span.red-background { background: red; }
405 span.silver-background { background: silver; }
406 span.teal-background { background: teal; }
407 span.white-background { background: white; }
408 span.yellow-background { background: yellow; }
410 span.big { font-size: 2em; }
411 span.small { font-size: 0.6em; }
413 span.underline { text-decoration: underline; }
414 span.overline { text-decoration: overline; }
415 span.line-through { text-decoration: line-through; }
417 div.unbreakable { page-break-inside: avoid; }
421 * xhtml11 specific
423 * */
425 div.tableblock {
426 margin-top: 1.0em;
427 margin-bottom: 1.5em;
429 div.tableblock > table {
430 border: 3px solid #527bbd;
432 thead, p.table.header {
433 font-weight: bold;
434 color: #527bbd;
436 p.table {
437 margin-top: 0;
439 /* Because the table frame attribute is overridden by CSS in most browsers. */
440 div.tableblock > table[frame="void"] {
441 border-style: none;
443 div.tableblock > table[frame="hsides"] {
444 border-left-style: none;
445 border-right-style: none;
447 div.tableblock > table[frame="vsides"] {
448 border-top-style: none;
449 border-bottom-style: none;
454 * html5 specific
456 * */
458 table.tableblock {
459 margin-top: 1.0em;
460 margin-bottom: 1.5em;
462 thead, p.tableblock.header {
463 font-weight: bold;
464 color: #527bbd;
466 p.tableblock {
467 margin-top: 0;
469 table.tableblock {
470 border-width: 3px;
471 border-spacing: 0px;
472 border-style: solid;
473 border-color: #527bbd;
474 border-collapse: collapse;
476 th.tableblock, td.tableblock {
477 border-width: 1px;
478 padding: 4px;
479 border-style: solid;
480 border-color: #527bbd;
483 table.tableblock.frame-topbot {
484 border-left-style: hidden;
485 border-right-style: hidden;
487 table.tableblock.frame-sides {
488 border-top-style: hidden;
489 border-bottom-style: hidden;
491 table.tableblock.frame-none {
492 border-style: hidden;
495 th.tableblock.halign-left, td.tableblock.halign-left {
496 text-align: left;
498 th.tableblock.halign-center, td.tableblock.halign-center {
499 text-align: center;
501 th.tableblock.halign-right, td.tableblock.halign-right {
502 text-align: right;
505 th.tableblock.valign-top, td.tableblock.valign-top {
506 vertical-align: top;
508 th.tableblock.valign-middle, td.tableblock.valign-middle {
509 vertical-align: middle;
511 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
512 vertical-align: bottom;
517 * manpage specific
519 * */
521 body.manpage h1 {
522 padding-top: 0.5em;
523 padding-bottom: 0.5em;
524 border-top: 2px solid silver;
525 border-bottom: 2px solid silver;
527 body.manpage h2 {
528 border-style: none;
530 body.manpage div.sectionbody {
531 margin-left: 3em;
534 @media print {
535 body.manpage div#toc { display: none; }
539 </style>
540 <script type="text/javascript">
541 /*<![CDATA[*/
542 var asciidoc = { // Namespace.
544 /////////////////////////////////////////////////////////////////////
545 // Table Of Contents generator
546 /////////////////////////////////////////////////////////////////////
548 /* Author: Mihai Bazon, September 2002
549 * http://students.infoiasi.ro/~mishoo
551 * Table Of Content generator
552 * Version: 0.4
554 * Feel free to use this script under the terms of the GNU General Public
555 * License, as long as you do not remove or alter this notice.
558 /* modified by Troy D. Hanson, September 2006. License: GPL */
559 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
561 // toclevels = 1..4.
562 toc: function (toclevels) {
564 function getText(el) {
565 var text = "";
566 for (var i = el.firstChild; i != null; i = i.nextSibling) {
567 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
568 text += i.data;
569 else if (i.firstChild != null)
570 text += getText(i);
572 return text;
575 function TocEntry(el, text, toclevel) {
576 this.element = el;
577 this.text = text;
578 this.toclevel = toclevel;
581 function tocEntries(el, toclevels) {
582 var result = new Array;
583 var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
584 // Function that scans the DOM tree for header elements (the DOM2
585 // nodeIterator API would be a better technique but not supported by all
586 // browsers).
587 var iterate = function (el) {
588 for (var i = el.firstChild; i != null; i = i.nextSibling) {
589 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
590 var mo = re.exec(i.tagName);
591 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
592 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
594 iterate(i);
598 iterate(el);
599 return result;
602 var toc = document.getElementById("toc");
603 if (!toc) {
604 return;
607 // Delete existing TOC entries in case we're reloading the TOC.
608 var tocEntriesToRemove = [];
609 var i;
610 for (i = 0; i < toc.childNodes.length; i++) {
611 var entry = toc.childNodes[i];
612 if (entry.nodeName.toLowerCase() == 'div'
613 && entry.getAttribute("class")
614 && entry.getAttribute("class").match(/^toclevel/))
615 tocEntriesToRemove.push(entry);
617 for (i = 0; i < tocEntriesToRemove.length; i++) {
618 toc.removeChild(tocEntriesToRemove[i]);
621 // Rebuild TOC entries.
622 var entries = tocEntries(document.getElementById("content"), toclevels);
623 for (var i = 0; i < entries.length; ++i) {
624 var entry = entries[i];
625 if (entry.element.id == "")
626 entry.element.id = "_toc_" + i;
627 var a = document.createElement("a");
628 a.href = "#" + entry.element.id;
629 a.appendChild(document.createTextNode(entry.text));
630 var div = document.createElement("div");
631 div.appendChild(a);
632 div.className = "toclevel" + entry.toclevel;
633 toc.appendChild(div);
635 if (entries.length == 0)
636 toc.parentNode.removeChild(toc);
640 /////////////////////////////////////////////////////////////////////
641 // Footnotes generator
642 /////////////////////////////////////////////////////////////////////
644 /* Based on footnote generation code from:
645 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
648 footnotes: function () {
649 // Delete existing footnote entries in case we're reloading the footnodes.
650 var i;
651 var noteholder = document.getElementById("footnotes");
652 if (!noteholder) {
653 return;
655 var entriesToRemove = [];
656 for (i = 0; i < noteholder.childNodes.length; i++) {
657 var entry = noteholder.childNodes[i];
658 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
659 entriesToRemove.push(entry);
661 for (i = 0; i < entriesToRemove.length; i++) {
662 noteholder.removeChild(entriesToRemove[i]);
665 // Rebuild footnote entries.
666 var cont = document.getElementById("content");
667 var spans = cont.getElementsByTagName("span");
668 var refs = {};
669 var n = 0;
670 for (i=0; i<spans.length; i++) {
671 if (spans[i].className == "footnote") {
672 n++;
673 var note = spans[i].getAttribute("data-note");
674 if (!note) {
675 // Use [\s\S] in place of . so multi-line matches work.
676 // Because JavaScript has no s (dotall) regex flag.
677 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
678 spans[i].innerHTML =
679 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
680 "' title='View footnote' class='footnote'>" + n + "</a>]";
681 spans[i].setAttribute("data-note", note);
683 noteholder.innerHTML +=
684 "<div class='footnote' id='_footnote_" + n + "'>" +
685 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
686 n + "</a>. " + note + "</div>";
687 var id =spans[i].getAttribute("id");
688 if (id != null) refs["#"+id] = n;
691 if (n == 0)
692 noteholder.parentNode.removeChild(noteholder);
693 else {
694 // Process footnoterefs.
695 for (i=0; i<spans.length; i++) {
696 if (spans[i].className == "footnoteref") {
697 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
698 href = href.match(/#.*/)[0]; // Because IE return full URL.
699 n = refs[href];
700 spans[i].innerHTML =
701 "[<a href='#_footnote_" + n +
702 "' title='View footnote' class='footnote'>" + n + "</a>]";
708 install: function(toclevels) {
709 var timerId;
711 function reinstall() {
712 asciidoc.footnotes();
713 if (toclevels) {
714 asciidoc.toc(toclevels);
718 function reinstallAndRemoveTimer() {
719 clearInterval(timerId);
720 reinstall();
723 timerId = setInterval(reinstall, 500);
724 if (document.addEventListener)
725 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
726 else
727 window.onload = reinstallAndRemoveTimer;
731 asciidoc.install();
732 /*]]>*/
733 </script>
734 </head>
735 <body class="manpage">
736 <div id="header">
737 <h1>
738 gitattributes(5) Manual Page
739 </h1>
740 <h2>NAME</h2>
741 <div class="sectionbody">
742 <p>gitattributes -
743 Defining attributes per path
744 </p>
745 </div>
746 </div>
747 <div id="content">
748 <div class="sect1">
749 <h2 id="_synopsis">SYNOPSIS</h2>
750 <div class="sectionbody">
751 <div class="paragraph"><p>$GIT_DIR/info/attributes, .gitattributes</p></div>
752 </div>
753 </div>
754 <div class="sect1">
755 <h2 id="_description">DESCRIPTION</h2>
756 <div class="sectionbody">
757 <div class="paragraph"><p>A <code>gitattributes</code> file is a simple text file that gives
758 <code>attributes</code> to pathnames.</p></div>
759 <div class="paragraph"><p>Each line in <code>gitattributes</code> file is of form:</p></div>
760 <div class="literalblock">
761 <div class="content">
762 <pre><code>pattern attr1 attr2 ...</code></pre>
763 </div></div>
764 <div class="paragraph"><p>That is, a pattern followed by an attributes list,
765 separated by whitespaces. Leading and trailing whitespaces are
766 ignored. Lines that begin with <em>#</em> are ignored. Patterns
767 that begin with a double quote are quoted in C style.
768 When the pattern matches the path in question, the attributes
769 listed on the line are given to the path.</p></div>
770 <div class="paragraph"><p>Each attribute can be in one of these states for a given path:</p></div>
771 <div class="dlist"><dl>
772 <dt class="hdlist1">
774 </dt>
775 <dd>
777 The path has the attribute with special value "true";
778 this is specified by listing only the name of the
779 attribute in the attribute list.
780 </p>
781 </dd>
782 <dt class="hdlist1">
783 Unset
784 </dt>
785 <dd>
787 The path has the attribute with special value "false";
788 this is specified by listing the name of the attribute
789 prefixed with a dash <code>-</code> in the attribute list.
790 </p>
791 </dd>
792 <dt class="hdlist1">
793 Set to a value
794 </dt>
795 <dd>
797 The path has the attribute with specified string value;
798 this is specified by listing the name of the attribute
799 followed by an equal sign <code>=</code> and its value in the
800 attribute list.
801 </p>
802 </dd>
803 <dt class="hdlist1">
804 Unspecified
805 </dt>
806 <dd>
808 No pattern matches the path, and nothing says if
809 the path has or does not have the attribute, the
810 attribute for the path is said to be Unspecified.
811 </p>
812 </dd>
813 </dl></div>
814 <div class="paragraph"><p>When more than one pattern matches the path, a later line
815 overrides an earlier line. This overriding is done per
816 attribute.</p></div>
817 <div class="paragraph"><p>The rules by which the pattern matches paths are the same as in
818 <code>.gitignore</code> files (see <a href="gitignore.html">gitignore(5)</a>), with a few exceptions:</p></div>
819 <div class="ulist"><ul>
820 <li>
822 negative patterns are forbidden
823 </p>
824 </li>
825 <li>
827 patterns that match a directory do not recursively match paths
828 inside that directory (so using the trailing-slash <code>path/</code> syntax is
829 pointless in an attributes file; use <code>path/**</code> instead)
830 </p>
831 </li>
832 </ul></div>
833 <div class="paragraph"><p>When deciding what attributes are assigned to a path, Git
834 consults <code>$GIT_DIR/info/attributes</code> file (which has the highest
835 precedence), <code>.gitattributes</code> file in the same directory as the
836 path in question, and its parent directories up to the toplevel of the
837 work tree (the further the directory that contains <code>.gitattributes</code>
838 is from the path in question, the lower its precedence). Finally
839 global and system-wide files are considered (they have the lowest
840 precedence).</p></div>
841 <div class="paragraph"><p>When the <code>.gitattributes</code> file is missing from the work tree, the
842 path in the index is used as a fall-back. During checkout process,
843 <code>.gitattributes</code> in the index is used and then the file in the
844 working tree is used as a fall-back.</p></div>
845 <div class="paragraph"><p>If you wish to affect only a single repository (i.e., to assign
846 attributes to files that are particular to
847 one user&#8217;s workflow for that repository), then
848 attributes should be placed in the <code>$GIT_DIR/info/attributes</code> file.
849 Attributes which should be version-controlled and distributed to other
850 repositories (i.e., attributes of interest to all users) should go into
851 <code>.gitattributes</code> files. Attributes that should affect all repositories
852 for a single user should be placed in a file specified by the
853 <code>core.attributesFile</code> configuration option (see <a href="git-config.html">git-config(1)</a>).
854 Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME
855 is either not set or empty, $HOME/.config/git/attributes is used instead.
856 Attributes for all users on a system should be placed in the
857 <code>$(prefix)/etc/gitattributes</code> file.</p></div>
858 <div class="paragraph"><p>Sometimes you would need to override a setting of an attribute
859 for a path to <code>Unspecified</code> state. This can be done by listing
860 the name of the attribute prefixed with an exclamation point <code>!</code>.</p></div>
861 </div>
862 </div>
863 <div class="sect1">
864 <h2 id="_reserved_builtin__attributes">RESERVED BUILTIN_* ATTRIBUTES</h2>
865 <div class="sectionbody">
866 <div class="paragraph"><p>builtin_* is a reserved namespace for builtin attribute values. Any
867 user defined attributes under this namespace will be ignored and
868 trigger a warning.</p></div>
869 <div class="sect2">
870 <h3 id="_code_builtin_objectmode_code"><code>builtin_objectmode</code></h3>
871 <div class="paragraph"><p>This attribute is for filtering files by their file bit modes (40000,
872 120000, 160000, 100755, 100644). e.g. <em>:(attr:builtin_objectmode=160000)</em>.
873 You may also check these values with <code>git check-attr builtin_objectmode -- &lt;file&gt;</code>.
874 If the object is not in the index <code>git check-attr --cached</code> will return unspecified.</p></div>
875 </div>
876 </div>
877 </div>
878 <div class="sect1">
879 <h2 id="_effects">EFFECTS</h2>
880 <div class="sectionbody">
881 <div class="paragraph"><p>Certain operations by Git can be influenced by assigning
882 particular attributes to a path. Currently, the following
883 operations are attributes-aware.</p></div>
884 <div class="sect2">
885 <h3 id="_checking_out_and_checking_in">Checking-out and checking-in</h3>
886 <div class="paragraph"><p>These attributes affect how the contents stored in the
887 repository are copied to the working tree files when commands
888 such as <em>git switch</em>, <em>git checkout</em> and <em>git merge</em> run.
889 They also affect how
890 Git stores the contents you prepare in the working tree in the
891 repository upon <em>git add</em> and <em>git commit</em>.</p></div>
892 <div class="sect3">
893 <h4 id="_code_text_code"><code>text</code></h4>
894 <div class="paragraph"><p>This attribute marks the path as a text file, which enables end-of-line
895 conversion: When a matching file is added to the index, the file&#8217;s line
896 endings are normalized to LF in the index. Conversely, when the file is
897 copied from the index to the working directory, its line endings may be
898 converted from LF to CRLF depending on the <code>eol</code> attribute, the Git
899 config, and the platform (see explanation of <code>eol</code> below).</p></div>
900 <div class="dlist"><dl>
901 <dt class="hdlist1">
903 </dt>
904 <dd>
906 Setting the <code>text</code> attribute on a path enables end-of-line
907 conversion on checkin and checkout as described above. Line endings
908 are normalized to LF in the index every time the file is checked in,
909 even if the file was previously added to Git with CRLF line endings.
910 </p>
911 </dd>
912 <dt class="hdlist1">
913 Unset
914 </dt>
915 <dd>
917 Unsetting the <code>text</code> attribute on a path tells Git not to
918 attempt any end-of-line conversion upon checkin or checkout.
919 </p>
920 </dd>
921 <dt class="hdlist1">
922 Set to string value "auto"
923 </dt>
924 <dd>
926 When <code>text</code> is set to "auto", Git decides by itself whether the file
927 is text or binary. If it is text and the file was not already in
928 Git with CRLF endings, line endings are converted on checkin and
929 checkout as described above. Otherwise, no conversion is done on
930 checkin or checkout.
931 </p>
932 </dd>
933 <dt class="hdlist1">
934 Unspecified
935 </dt>
936 <dd>
938 If the <code>text</code> attribute is unspecified, Git uses the
939 <code>core.autocrlf</code> configuration variable to determine if the
940 file should be converted.
941 </p>
942 </dd>
943 </dl></div>
944 <div class="paragraph"><p>Any other value causes Git to act as if <code>text</code> has been left
945 unspecified.</p></div>
946 </div>
947 <div class="sect3">
948 <h4 id="_code_eol_code"><code>eol</code></h4>
949 <div class="paragraph"><p>This attribute marks a path to use a specific line-ending style in the
950 working tree when it is checked out. It has effect only if <code>text</code> or
951 <code>text=auto</code> is set (see above), but specifying <code>eol</code> automatically sets
952 <code>text</code> if <code>text</code> was left unspecified.</p></div>
953 <div class="dlist"><dl>
954 <dt class="hdlist1">
955 Set to string value "crlf"
956 </dt>
957 <dd>
959 This setting converts the file&#8217;s line endings in the working
960 directory to CRLF when the file is checked out.
961 </p>
962 </dd>
963 <dt class="hdlist1">
964 Set to string value "lf"
965 </dt>
966 <dd>
968 This setting uses the same line endings in the working directory as
969 in the index when the file is checked out.
970 </p>
971 </dd>
972 <dt class="hdlist1">
973 Unspecified
974 </dt>
975 <dd>
977 If the <code>eol</code> attribute is unspecified for a file, its line endings
978 in the working directory are determined by the <code>core.autocrlf</code> or
979 <code>core.eol</code> configuration variable (see the definitions of those
980 options in <a href="git-config.html">git-config(1)</a>). If <code>text</code> is set but neither of
981 those variables is, the default is <code>eol=crlf</code> on Windows and
982 <code>eol=lf</code> on all other platforms.
983 </p>
984 </dd>
985 </dl></div>
986 </div>
987 <div class="sect3">
988 <h4 id="_backwards_compatibility_with_code_crlf_code_attribute">Backwards compatibility with <code>crlf</code> attribute</h4>
989 <div class="paragraph"><p>For backwards compatibility, the <code>crlf</code> attribute is interpreted as
990 follows:</p></div>
991 <div class="listingblock">
992 <div class="content">
993 <pre><code>crlf text
994 -crlf -text
995 crlf=input eol=lf</code></pre>
996 </div></div>
997 </div>
998 <div class="sect3">
999 <h4 id="_end_of_line_conversion">End-of-line conversion</h4>
1000 <div class="paragraph"><p>While Git normally leaves file contents alone, it can be configured to
1001 normalize line endings to LF in the repository and, optionally, to
1002 convert them to CRLF when files are checked out.</p></div>
1003 <div class="paragraph"><p>If you simply want to have CRLF line endings in your working directory
1004 regardless of the repository you are working with, you can set the
1005 config variable "core.autocrlf" without using any attributes.</p></div>
1006 <div class="listingblock">
1007 <div class="content">
1008 <pre><code>[core]
1009 autocrlf = true</code></pre>
1010 </div></div>
1011 <div class="paragraph"><p>This does not force normalization of text files, but does ensure
1012 that text files that you introduce to the repository have their line
1013 endings normalized to LF when they are added, and that files that are
1014 already normalized in the repository stay normalized.</p></div>
1015 <div class="paragraph"><p>If you want to ensure that text files that any contributor introduces to
1016 the repository have their line endings normalized, you can set the
1017 <code>text</code> attribute to "auto" for <em>all</em> files.</p></div>
1018 <div class="listingblock">
1019 <div class="content">
1020 <pre><code>* text=auto</code></pre>
1021 </div></div>
1022 <div class="paragraph"><p>The attributes allow a fine-grained control, how the line endings
1023 are converted.
1024 Here is an example that will make Git normalize .txt, .vcproj and .sh
1025 files, ensure that .vcproj files have CRLF and .sh files have LF in
1026 the working directory, and prevent .jpg files from being normalized
1027 regardless of their content.</p></div>
1028 <div class="listingblock">
1029 <div class="content">
1030 <pre><code>* text=auto
1031 *.txt text
1032 *.vcproj text eol=crlf
1033 *.sh text eol=lf
1034 *.jpg -text</code></pre>
1035 </div></div>
1036 <div class="admonitionblock">
1037 <table><tr>
1038 <td class="icon">
1039 <div class="title">Note</div>
1040 </td>
1041 <td class="content">When <code>text=auto</code> conversion is enabled in a cross-platform
1042 project using push and pull to a central repository the text files
1043 containing CRLFs should be normalized.</td>
1044 </tr></table>
1045 </div>
1046 <div class="paragraph"><p>From a clean working directory:</p></div>
1047 <div class="listingblock">
1048 <div class="content">
1049 <pre><code>$ echo "* text=auto" &gt;.gitattributes
1050 $ git add --renormalize .
1051 $ git status # Show files that will be normalized
1052 $ git commit -m "Introduce end-of-line normalization"</code></pre>
1053 </div></div>
1054 <div class="paragraph"><p>If any files that should not be normalized show up in <em>git status</em>,
1055 unset their <code>text</code> attribute before running <em>git add -u</em>.</p></div>
1056 <div class="listingblock">
1057 <div class="content">
1058 <pre><code>manual.pdf -text</code></pre>
1059 </div></div>
1060 <div class="paragraph"><p>Conversely, text files that Git does not detect can have normalization
1061 enabled manually.</p></div>
1062 <div class="listingblock">
1063 <div class="content">
1064 <pre><code>weirdchars.txt text</code></pre>
1065 </div></div>
1066 <div class="paragraph"><p>If <code>core.safecrlf</code> is set to "true" or "warn", Git verifies if
1067 the conversion is reversible for the current setting of
1068 <code>core.autocrlf</code>. For "true", Git rejects irreversible
1069 conversions; for "warn", Git only prints a warning but accepts
1070 an irreversible conversion. The safety triggers to prevent such
1071 a conversion done to the files in the work tree, but there are a
1072 few exceptions. Even though&#8230;</p></div>
1073 <div class="ulist"><ul>
1074 <li>
1076 <em>git add</em> itself does not touch the files in the work tree, the
1077 next checkout would, so the safety triggers;
1078 </p>
1079 </li>
1080 <li>
1082 <em>git apply</em> to update a text file with a patch does touch the files
1083 in the work tree, but the operation is about text files and CRLF
1084 conversion is about fixing the line ending inconsistencies, so the
1085 safety does not trigger;
1086 </p>
1087 </li>
1088 <li>
1090 <em>git diff</em> itself does not touch the files in the work tree, it is
1091 often run to inspect the changes you intend to next <em>git add</em>. To
1092 catch potential problems early, safety triggers.
1093 </p>
1094 </li>
1095 </ul></div>
1096 </div>
1097 <div class="sect3">
1098 <h4 id="_code_working_tree_encoding_code"><code>working-tree-encoding</code></h4>
1099 <div class="paragraph"><p>Git recognizes files encoded in ASCII or one of its supersets (e.g.
1100 UTF-8, ISO-8859-1, &#8230;) as text files. Files encoded in certain other
1101 encodings (e.g. UTF-16) are interpreted as binary and consequently
1102 built-in Git text processing tools (e.g. <em>git diff</em>) as well as most Git
1103 web front ends do not visualize the contents of these files by default.</p></div>
1104 <div class="paragraph"><p>In these cases you can tell Git the encoding of a file in the working
1105 directory with the <code>working-tree-encoding</code> attribute. If a file with this
1106 attribute is added to Git, then Git re-encodes the content from the
1107 specified encoding to UTF-8. Finally, Git stores the UTF-8 encoded
1108 content in its internal data structure (called "the index"). On checkout
1109 the content is re-encoded back to the specified encoding.</p></div>
1110 <div class="paragraph"><p>Please note that using the <code>working-tree-encoding</code> attribute may have a
1111 number of pitfalls:</p></div>
1112 <div class="ulist"><ul>
1113 <li>
1115 Alternative Git implementations (e.g. JGit or libgit2) and older Git
1116 versions (as of March 2018) do not support the <code>working-tree-encoding</code>
1117 attribute. If you decide to use the <code>working-tree-encoding</code> attribute
1118 in your repository, then it is strongly recommended to ensure that all
1119 clients working with the repository support it.
1120 </p>
1121 <div class="paragraph"><p>For example, Microsoft Visual Studio resources files (<code>*.rc</code>) or
1122 PowerShell script files (<code>*.ps1</code>) are sometimes encoded in UTF-16.
1123 If you declare <code>*.ps1</code> as files as UTF-16 and you add <code>foo.ps1</code> with
1124 a <code>working-tree-encoding</code> enabled Git client, then <code>foo.ps1</code> will be
1125 stored as UTF-8 internally. A client without <code>working-tree-encoding</code>
1126 support will checkout <code>foo.ps1</code> as UTF-8 encoded file. This will
1127 typically cause trouble for the users of this file.</p></div>
1128 <div class="paragraph"><p>If a Git client that does not support the <code>working-tree-encoding</code>
1129 attribute adds a new file <code>bar.ps1</code>, then <code>bar.ps1</code> will be
1130 stored "as-is" internally (in this example probably as UTF-16).
1131 A client with <code>working-tree-encoding</code> support will interpret the
1132 internal contents as UTF-8 and try to convert it to UTF-16 on checkout.
1133 That operation will fail and cause an error.</p></div>
1134 </li>
1135 <li>
1137 Reencoding content to non-UTF encodings can cause errors as the
1138 conversion might not be UTF-8 round trip safe. If you suspect your
1139 encoding to not be round trip safe, then add it to
1140 <code>core.checkRoundtripEncoding</code> to make Git check the round trip
1141 encoding (see <a href="git-config.html">git-config(1)</a>). SHIFT-JIS (Japanese character
1142 set) is known to have round trip issues with UTF-8 and is checked by
1143 default.
1144 </p>
1145 </li>
1146 <li>
1148 Reencoding content requires resources that might slow down certain
1149 Git operations (e.g <em>git checkout</em> or <em>git add</em>).
1150 </p>
1151 </li>
1152 </ul></div>
1153 <div class="paragraph"><p>Use the <code>working-tree-encoding</code> attribute only if you cannot store a file
1154 in UTF-8 encoding and if you want Git to be able to process the content
1155 as text.</p></div>
1156 <div class="paragraph"><p>As an example, use the following attributes if your <em>*.ps1</em> files are
1157 UTF-16 encoded with byte order mark (BOM) and you want Git to perform
1158 automatic line ending conversion based on your platform.</p></div>
1159 <div class="listingblock">
1160 <div class="content">
1161 <pre><code>*.ps1 text working-tree-encoding=UTF-16</code></pre>
1162 </div></div>
1163 <div class="paragraph"><p>Use the following attributes if your <em>*.ps1</em> files are UTF-16 little
1164 endian encoded without BOM and you want Git to use Windows line endings
1165 in the working directory (use <code>UTF-16LE-BOM</code> instead of <code>UTF-16LE</code> if
1166 you want UTF-16 little endian with BOM).
1167 Please note, it is highly recommended to
1168 explicitly define the line endings with <code>eol</code> if the <code>working-tree-encoding</code>
1169 attribute is used to avoid ambiguity.</p></div>
1170 <div class="listingblock">
1171 <div class="content">
1172 <pre><code>*.ps1 text working-tree-encoding=UTF-16LE eol=CRLF</code></pre>
1173 </div></div>
1174 <div class="paragraph"><p>You can get a list of all available encodings on your platform with the
1175 following command:</p></div>
1176 <div class="listingblock">
1177 <div class="content">
1178 <pre><code>iconv --list</code></pre>
1179 </div></div>
1180 <div class="paragraph"><p>If you do not know the encoding of a file, then you can use the <code>file</code>
1181 command to guess the encoding:</p></div>
1182 <div class="listingblock">
1183 <div class="content">
1184 <pre><code>file foo.ps1</code></pre>
1185 </div></div>
1186 </div>
1187 <div class="sect3">
1188 <h4 id="_code_ident_code"><code>ident</code></h4>
1189 <div class="paragraph"><p>When the attribute <code>ident</code> is set for a path, Git replaces
1190 <code>$Id$</code> in the blob object with <code>$Id:</code>, followed by the
1191 40-character hexadecimal blob object name, followed by a dollar
1192 sign <code>$</code> upon checkout. Any byte sequence that begins with
1193 <code>$Id:</code> and ends with <code>$</code> in the worktree file is replaced
1194 with <code>$Id$</code> upon check-in.</p></div>
1195 </div>
1196 <div class="sect3">
1197 <h4 id="_code_filter_code"><code>filter</code></h4>
1198 <div class="paragraph"><p>A <code>filter</code> attribute can be set to a string value that names a
1199 filter driver specified in the configuration.</p></div>
1200 <div class="paragraph"><p>A filter driver consists of a <code>clean</code> command and a <code>smudge</code>
1201 command, either of which can be left unspecified. Upon
1202 checkout, when the <code>smudge</code> command is specified, the command is
1203 fed the blob object from its standard input, and its standard
1204 output is used to update the worktree file. Similarly, the
1205 <code>clean</code> command is used to convert the contents of worktree file
1206 upon checkin. By default these commands process only a single
1207 blob and terminate. If a long running <code>process</code> filter is used
1208 in place of <code>clean</code> and/or <code>smudge</code> filters, then Git can process
1209 all blobs with a single filter command invocation for the entire
1210 life of a single Git command, for example <code>git add --all</code>. If a
1211 long running <code>process</code> filter is configured then it always takes
1212 precedence over a configured single blob filter. See section
1213 below for the description of the protocol used to communicate with
1214 a <code>process</code> filter.</p></div>
1215 <div class="paragraph"><p>One use of the content filtering is to massage the content into a shape
1216 that is more convenient for the platform, filesystem, and the user to use.
1217 For this mode of operation, the key phrase here is "more convenient" and
1218 not "turning something unusable into usable". In other words, the intent
1219 is that if someone unsets the filter driver definition, or does not have
1220 the appropriate filter program, the project should still be usable.</p></div>
1221 <div class="paragraph"><p>Another use of the content filtering is to store the content that cannot
1222 be directly used in the repository (e.g. a UUID that refers to the true
1223 content stored outside Git, or an encrypted content) and turn it into a
1224 usable form upon checkout (e.g. download the external content, or decrypt
1225 the encrypted content).</p></div>
1226 <div class="paragraph"><p>These two filters behave differently, and by default, a filter is taken as
1227 the former, massaging the contents into more convenient shape. A missing
1228 filter driver definition in the config, or a filter driver that exits with
1229 a non-zero status, is not an error but makes the filter a no-op passthru.</p></div>
1230 <div class="paragraph"><p>You can declare that a filter turns a content that by itself is unusable
1231 into a usable content by setting the filter.&lt;driver&gt;.required configuration
1232 variable to <code>true</code>.</p></div>
1233 <div class="paragraph"><p>Note: Whenever the clean filter is changed, the repo should be renormalized:
1234 $ git add --renormalize .</p></div>
1235 <div class="paragraph"><p>For example, in .gitattributes, you would assign the <code>filter</code>
1236 attribute for paths.</p></div>
1237 <div class="listingblock">
1238 <div class="content">
1239 <pre><code>*.c filter=indent</code></pre>
1240 </div></div>
1241 <div class="paragraph"><p>Then you would define a "filter.indent.clean" and "filter.indent.smudge"
1242 configuration in your .git/config to specify a pair of commands to
1243 modify the contents of C programs when the source files are checked
1244 in ("clean" is run) and checked out (no change is made because the
1245 command is "cat").</p></div>
1246 <div class="listingblock">
1247 <div class="content">
1248 <pre><code>[filter "indent"]
1249 clean = indent
1250 smudge = cat</code></pre>
1251 </div></div>
1252 <div class="paragraph"><p>For best results, <code>clean</code> should not alter its output further if it is
1253 run twice ("clean&#8594;clean" should be equivalent to "clean"), and
1254 multiple <code>smudge</code> commands should not alter <code>clean</code>'s output
1255 ("smudge&#8594;smudge&#8594;clean" should be equivalent to "clean"). See the
1256 section on merging below.</p></div>
1257 <div class="paragraph"><p>The "indent" filter is well-behaved in this regard: it will not modify
1258 input that is already correctly indented. In this case, the lack of a
1259 smudge filter means that the clean filter <em>must</em> accept its own output
1260 without modifying it.</p></div>
1261 <div class="paragraph"><p>If a filter <em>must</em> succeed in order to make the stored contents usable,
1262 you can declare that the filter is <code>required</code>, in the configuration:</p></div>
1263 <div class="listingblock">
1264 <div class="content">
1265 <pre><code>[filter "crypt"]
1266 clean = openssl enc ...
1267 smudge = openssl enc -d ...
1268 required</code></pre>
1269 </div></div>
1270 <div class="paragraph"><p>Sequence "%f" on the filter command line is replaced with the name of
1271 the file the filter is working on. A filter might use this in keyword
1272 substitution. For example:</p></div>
1273 <div class="listingblock">
1274 <div class="content">
1275 <pre><code>[filter "p4"]
1276 clean = git-p4-filter --clean %f
1277 smudge = git-p4-filter --smudge %f</code></pre>
1278 </div></div>
1279 <div class="paragraph"><p>Note that "%f" is the name of the path that is being worked on. Depending
1280 on the version that is being filtered, the corresponding file on disk may
1281 not exist, or may have different contents. So, smudge and clean commands
1282 should not try to access the file on disk, but only act as filters on the
1283 content provided to them on standard input.</p></div>
1284 </div>
1285 <div class="sect3">
1286 <h4 id="_long_running_filter_process">Long Running Filter Process</h4>
1287 <div class="paragraph"><p>If the filter command (a string value) is defined via
1288 <code>filter.&lt;driver&gt;.process</code> then Git can process all blobs with a
1289 single filter invocation for the entire life of a single Git
1290 command. This is achieved by using the long-running process protocol
1291 (described in technical/long-running-process-protocol.txt).</p></div>
1292 <div class="paragraph"><p>When Git encounters the first file that needs to be cleaned or smudged,
1293 it starts the filter and performs the handshake. In the handshake, the
1294 welcome message sent by Git is "git-filter-client", only version 2 is
1295 supported, and the supported capabilities are "clean", "smudge", and
1296 "delay".</p></div>
1297 <div class="paragraph"><p>Afterwards Git sends a list of "key=value" pairs terminated with
1298 a flush packet. The list will contain at least the filter command
1299 (based on the supported capabilities) and the pathname of the file
1300 to filter relative to the repository root. Right after the flush packet
1301 Git sends the content split in zero or more pkt-line packets and a
1302 flush packet to terminate content. Please note, that the filter
1303 must not send any response before it received the content and the
1304 final flush packet. Also note that the "value" of a "key=value" pair
1305 can contain the "=" character whereas the key would never contain
1306 that character.</p></div>
1307 <div class="listingblock">
1308 <div class="content">
1309 <pre><code>packet: git&gt; command=smudge
1310 packet: git&gt; pathname=path/testfile.dat
1311 packet: git&gt; 0000
1312 packet: git&gt; CONTENT
1313 packet: git&gt; 0000</code></pre>
1314 </div></div>
1315 <div class="paragraph"><p>The filter is expected to respond with a list of "key=value" pairs
1316 terminated with a flush packet. If the filter does not experience
1317 problems then the list must contain a "success" status. Right after
1318 these packets the filter is expected to send the content in zero
1319 or more pkt-line packets and a flush packet at the end. Finally, a
1320 second list of "key=value" pairs terminated with a flush packet
1321 is expected. The filter can change the status in the second list
1322 or keep the status as is with an empty list. Please note that the
1323 empty list must be terminated with a flush packet regardless.</p></div>
1324 <div class="listingblock">
1325 <div class="content">
1326 <pre><code>packet: git&lt; status=success
1327 packet: git&lt; 0000
1328 packet: git&lt; SMUDGED_CONTENT
1329 packet: git&lt; 0000
1330 packet: git&lt; 0000 # empty list, keep "status=success" unchanged!</code></pre>
1331 </div></div>
1332 <div class="paragraph"><p>If the result content is empty then the filter is expected to respond
1333 with a "success" status and a flush packet to signal the empty content.</p></div>
1334 <div class="listingblock">
1335 <div class="content">
1336 <pre><code>packet: git&lt; status=success
1337 packet: git&lt; 0000
1338 packet: git&lt; 0000 # empty content!
1339 packet: git&lt; 0000 # empty list, keep "status=success" unchanged!</code></pre>
1340 </div></div>
1341 <div class="paragraph"><p>In case the filter cannot or does not want to process the content,
1342 it is expected to respond with an "error" status.</p></div>
1343 <div class="listingblock">
1344 <div class="content">
1345 <pre><code>packet: git&lt; status=error
1346 packet: git&lt; 0000</code></pre>
1347 </div></div>
1348 <div class="paragraph"><p>If the filter experiences an error during processing, then it can
1349 send the status "error" after the content was (partially or
1350 completely) sent.</p></div>
1351 <div class="listingblock">
1352 <div class="content">
1353 <pre><code>packet: git&lt; status=success
1354 packet: git&lt; 0000
1355 packet: git&lt; HALF_WRITTEN_ERRONEOUS_CONTENT
1356 packet: git&lt; 0000
1357 packet: git&lt; status=error
1358 packet: git&lt; 0000</code></pre>
1359 </div></div>
1360 <div class="paragraph"><p>In case the filter cannot or does not want to process the content
1361 as well as any future content for the lifetime of the Git process,
1362 then it is expected to respond with an "abort" status at any point
1363 in the protocol.</p></div>
1364 <div class="listingblock">
1365 <div class="content">
1366 <pre><code>packet: git&lt; status=abort
1367 packet: git&lt; 0000</code></pre>
1368 </div></div>
1369 <div class="paragraph"><p>Git neither stops nor restarts the filter process in case the
1370 "error"/"abort" status is set. However, Git sets its exit code
1371 according to the <code>filter.&lt;driver&gt;.required</code> flag, mimicking the
1372 behavior of the <code>filter.&lt;driver&gt;.clean</code> / <code>filter.&lt;driver&gt;.smudge</code>
1373 mechanism.</p></div>
1374 <div class="paragraph"><p>If the filter dies during the communication or does not adhere to
1375 the protocol then Git will stop the filter process and restart it
1376 with the next file that needs to be processed. Depending on the
1377 <code>filter.&lt;driver&gt;.required</code> flag Git will interpret that as error.</p></div>
1378 </div>
1379 <div class="sect3">
1380 <h4 id="_delay">Delay</h4>
1381 <div class="paragraph"><p>If the filter supports the "delay" capability, then Git can send the
1382 flag "can-delay" after the filter command and pathname. This flag
1383 denotes that the filter can delay filtering the current blob (e.g. to
1384 compensate network latencies) by responding with no content but with
1385 the status "delayed" and a flush packet.</p></div>
1386 <div class="listingblock">
1387 <div class="content">
1388 <pre><code>packet: git&gt; command=smudge
1389 packet: git&gt; pathname=path/testfile.dat
1390 packet: git&gt; can-delay=1
1391 packet: git&gt; 0000
1392 packet: git&gt; CONTENT
1393 packet: git&gt; 0000
1394 packet: git&lt; status=delayed
1395 packet: git&lt; 0000</code></pre>
1396 </div></div>
1397 <div class="paragraph"><p>If the filter supports the "delay" capability then it must support the
1398 "list_available_blobs" command. If Git sends this command, then the
1399 filter is expected to return a list of pathnames representing blobs
1400 that have been delayed earlier and are now available.
1401 The list must be terminated with a flush packet followed
1402 by a "success" status that is also terminated with a flush packet. If
1403 no blobs for the delayed paths are available, yet, then the filter is
1404 expected to block the response until at least one blob becomes
1405 available. The filter can tell Git that it has no more delayed blobs
1406 by sending an empty list. As soon as the filter responds with an empty
1407 list, Git stops asking. All blobs that Git has not received at this
1408 point are considered missing and will result in an error.</p></div>
1409 <div class="listingblock">
1410 <div class="content">
1411 <pre><code>packet: git&gt; command=list_available_blobs
1412 packet: git&gt; 0000
1413 packet: git&lt; pathname=path/testfile.dat
1414 packet: git&lt; pathname=path/otherfile.dat
1415 packet: git&lt; 0000
1416 packet: git&lt; status=success
1417 packet: git&lt; 0000</code></pre>
1418 </div></div>
1419 <div class="paragraph"><p>After Git received the pathnames, it will request the corresponding
1420 blobs again. These requests contain a pathname and an empty content
1421 section. The filter is expected to respond with the smudged content
1422 in the usual way as explained above.</p></div>
1423 <div class="listingblock">
1424 <div class="content">
1425 <pre><code>packet: git&gt; command=smudge
1426 packet: git&gt; pathname=path/testfile.dat
1427 packet: git&gt; 0000
1428 packet: git&gt; 0000 # empty content!
1429 packet: git&lt; status=success
1430 packet: git&lt; 0000
1431 packet: git&lt; SMUDGED_CONTENT
1432 packet: git&lt; 0000
1433 packet: git&lt; 0000 # empty list, keep "status=success" unchanged!</code></pre>
1434 </div></div>
1435 </div>
1436 <div class="sect3">
1437 <h4 id="_example">Example</h4>
1438 <div class="paragraph"><p>A long running filter demo implementation can be found in
1439 <code>contrib/long-running-filter/example.pl</code> located in the Git
1440 core repository. If you develop your own long running filter
1441 process then the <code>GIT_TRACE_PACKET</code> environment variables can be
1442 very helpful for debugging (see <a href="git.html">git(1)</a>).</p></div>
1443 <div class="paragraph"><p>Please note that you cannot use an existing <code>filter.&lt;driver&gt;.clean</code>
1444 or <code>filter.&lt;driver&gt;.smudge</code> command with <code>filter.&lt;driver&gt;.process</code>
1445 because the former two use a different inter process communication
1446 protocol than the latter one.</p></div>
1447 </div>
1448 <div class="sect3">
1449 <h4 id="_interaction_between_checkin_checkout_attributes">Interaction between checkin/checkout attributes</h4>
1450 <div class="paragraph"><p>In the check-in codepath, the worktree file is first converted
1451 with <code>filter</code> driver (if specified and corresponding driver
1452 defined), then the result is processed with <code>ident</code> (if
1453 specified), and then finally with <code>text</code> (again, if specified
1454 and applicable).</p></div>
1455 <div class="paragraph"><p>In the check-out codepath, the blob content is first converted
1456 with <code>text</code>, and then <code>ident</code> and fed to <code>filter</code>.</p></div>
1457 </div>
1458 <div class="sect3">
1459 <h4 id="_merging_branches_with_differing_checkin_checkout_attributes">Merging branches with differing checkin/checkout attributes</h4>
1460 <div class="paragraph"><p>If you have added attributes to a file that cause the canonical
1461 repository format for that file to change, such as adding a
1462 clean/smudge filter or text/eol/ident attributes, merging anything
1463 where the attribute is not in place would normally cause merge
1464 conflicts.</p></div>
1465 <div class="paragraph"><p>To prevent these unnecessary merge conflicts, Git can be told to run a
1466 virtual check-out and check-in of all three stages of a file when
1467 resolving a three-way merge by setting the <code>merge.renormalize</code>
1468 configuration variable. This prevents changes caused by check-in
1469 conversion from causing spurious merge conflicts when a converted file
1470 is merged with an unconverted file.</p></div>
1471 <div class="paragraph"><p>As long as a "smudge&#8594;clean" results in the same output as a "clean"
1472 even on files that are already smudged, this strategy will
1473 automatically resolve all filter-related conflicts. Filters that do
1474 not act in this way may cause additional merge conflicts that must be
1475 resolved manually.</p></div>
1476 </div>
1477 </div>
1478 <div class="sect2">
1479 <h3 id="_generating_diff_text">Generating diff text</h3>
1480 <div class="sect3">
1481 <h4 id="_code_diff_code"><code>diff</code></h4>
1482 <div class="paragraph"><p>The attribute <code>diff</code> affects how Git generates diffs for particular
1483 files. It can tell Git whether to generate a textual patch for the path
1484 or to treat the path as a binary file. It can also affect what line is
1485 shown on the hunk header <code>@@ -k,l +n,m @@</code> line, tell Git to use an
1486 external command to generate the diff, or ask Git to convert binary
1487 files to a text format before generating the diff.</p></div>
1488 <div class="dlist"><dl>
1489 <dt class="hdlist1">
1491 </dt>
1492 <dd>
1494 A path to which the <code>diff</code> attribute is set is treated
1495 as text, even when they contain byte values that
1496 normally never appear in text files, such as NUL.
1497 </p>
1498 </dd>
1499 <dt class="hdlist1">
1500 Unset
1501 </dt>
1502 <dd>
1504 A path to which the <code>diff</code> attribute is unset will
1505 generate <code>Binary files differ</code> (or a binary patch, if
1506 binary patches are enabled).
1507 </p>
1508 </dd>
1509 <dt class="hdlist1">
1510 Unspecified
1511 </dt>
1512 <dd>
1514 A path to which the <code>diff</code> attribute is unspecified
1515 first gets its contents inspected, and if it looks like
1516 text and is smaller than core.bigFileThreshold, it is treated
1517 as text. Otherwise it would generate <code>Binary files differ</code>.
1518 </p>
1519 </dd>
1520 <dt class="hdlist1">
1521 String
1522 </dt>
1523 <dd>
1525 Diff is shown using the specified diff driver. Each driver may
1526 specify one or more options, as described in the following
1527 section. The options for the diff driver "foo" are defined
1528 by the configuration variables in the "diff.foo" section of the
1529 Git config file.
1530 </p>
1531 </dd>
1532 </dl></div>
1533 </div>
1534 <div class="sect3">
1535 <h4 id="_defining_an_external_diff_driver">Defining an external diff driver</h4>
1536 <div class="paragraph"><p>The definition of a diff driver is done in <code>gitconfig</code>, not
1537 <code>gitattributes</code> file, so strictly speaking this manual page is a
1538 wrong place to talk about it. However&#8230;</p></div>
1539 <div class="paragraph"><p>To define an external diff driver <code>jcdiff</code>, add a section to your
1540 <code>$GIT_DIR/config</code> file (or <code>$HOME/.gitconfig</code> file) like this:</p></div>
1541 <div class="listingblock">
1542 <div class="content">
1543 <pre><code>[diff "jcdiff"]
1544 command = j-c-diff</code></pre>
1545 </div></div>
1546 <div class="paragraph"><p>When Git needs to show you a diff for the path with <code>diff</code>
1547 attribute set to <code>jcdiff</code>, it calls the command you specified
1548 with the above configuration, i.e. <code>j-c-diff</code>, with 7
1549 parameters, just like <code>GIT_EXTERNAL_DIFF</code> program is called.
1550 See <a href="git.html">git(1)</a> for details.</p></div>
1551 </div>
1552 <div class="sect3">
1553 <h4 id="_setting_the_internal_diff_algorithm">Setting the internal diff algorithm</h4>
1554 <div class="paragraph"><p>The diff algorithm can be set through the <code>diff.algorithm</code> config key, but
1555 sometimes it may be helpful to set the diff algorithm per path. For example,
1556 one may want to use the <code>minimal</code> diff algorithm for .json files, and the
1557 <code>histogram</code> for .c files, and so on without having to pass in the algorithm
1558 through the command line each time.</p></div>
1559 <div class="paragraph"><p>First, in <code>.gitattributes</code>, assign the <code>diff</code> attribute for paths.</p></div>
1560 <div class="listingblock">
1561 <div class="content">
1562 <pre><code>*.json diff=&lt;name&gt;</code></pre>
1563 </div></div>
1564 <div class="paragraph"><p>Then, define a "diff.&lt;name&gt;.algorithm" configuration to specify the diff
1565 algorithm, choosing from <code>myers</code>, <code>patience</code>, <code>minimal</code>, or <code>histogram</code>.</p></div>
1566 <div class="listingblock">
1567 <div class="content">
1568 <pre><code>[diff "&lt;name&gt;"]
1569 algorithm = histogram</code></pre>
1570 </div></div>
1571 <div class="paragraph"><p>This diff algorithm applies to user facing diff output like git-diff(1),
1572 git-show(1) and is used for the <code>--stat</code> output as well. The merge machinery
1573 will not use the diff algorithm set through this method.</p></div>
1574 <div class="admonitionblock">
1575 <table><tr>
1576 <td class="icon">
1577 <div class="title">Note</div>
1578 </td>
1579 <td class="content">If <code>diff.&lt;name&gt;.command</code> is defined for path with the
1580 <code>diff=&lt;name&gt;</code> attribute, it is executed as an external diff driver
1581 (see above), and adding <code>diff.&lt;name&gt;.algorithm</code> has no effect, as the
1582 algorithm is not passed to the external diff driver.</td>
1583 </tr></table>
1584 </div>
1585 </div>
1586 <div class="sect3">
1587 <h4 id="_defining_a_custom_hunk_header">Defining a custom hunk-header</h4>
1588 <div class="paragraph"><p>Each group of changes (called a "hunk") in the textual diff output
1589 is prefixed with a line of the form:</p></div>
1590 <div class="literalblock">
1591 <div class="content">
1592 <pre><code>@@ -k,l +n,m @@ TEXT</code></pre>
1593 </div></div>
1594 <div class="paragraph"><p>This is called a <em>hunk header</em>. The "TEXT" portion is by default a line
1595 that begins with an alphabet, an underscore or a dollar sign; this
1596 matches what GNU <em>diff -p</em> output uses. This default selection however
1597 is not suited for some contents, and you can use a customized pattern
1598 to make a selection.</p></div>
1599 <div class="paragraph"><p>First, in .gitattributes, you would assign the <code>diff</code> attribute
1600 for paths.</p></div>
1601 <div class="listingblock">
1602 <div class="content">
1603 <pre><code>*.tex diff=tex</code></pre>
1604 </div></div>
1605 <div class="paragraph"><p>Then, you would define a "diff.tex.xfuncname" configuration to
1606 specify a regular expression that matches a line that you would
1607 want to appear as the hunk header "TEXT". Add a section to your
1608 <code>$GIT_DIR/config</code> file (or <code>$HOME/.gitconfig</code> file) like this:</p></div>
1609 <div class="listingblock">
1610 <div class="content">
1611 <pre><code>[diff "tex"]
1612 xfuncname = "^(\\\\(sub)*section\\{.*)$"</code></pre>
1613 </div></div>
1614 <div class="paragraph"><p>Note. A single level of backslashes are eaten by the
1615 configuration file parser, so you would need to double the
1616 backslashes; the pattern above picks a line that begins with a
1617 backslash, and zero or more occurrences of <code>sub</code> followed by
1618 <code>section</code> followed by open brace, to the end of line.</p></div>
1619 <div class="paragraph"><p>There are a few built-in patterns to make this easier, and <code>tex</code>
1620 is one of them, so you do not have to write the above in your
1621 configuration file (you still need to enable this with the
1622 attribute mechanism, via <code>.gitattributes</code>). The following built in
1623 patterns are available:</p></div>
1624 <div class="ulist"><ul>
1625 <li>
1627 <code>ada</code> suitable for source code in the Ada language.
1628 </p>
1629 </li>
1630 <li>
1632 <code>bash</code> suitable for source code in the Bourne-Again SHell language.
1633 Covers a superset of POSIX shell function definitions.
1634 </p>
1635 </li>
1636 <li>
1638 <code>bibtex</code> suitable for files with BibTeX coded references.
1639 </p>
1640 </li>
1641 <li>
1643 <code>cpp</code> suitable for source code in the C and C++ languages.
1644 </p>
1645 </li>
1646 <li>
1648 <code>csharp</code> suitable for source code in the C# language.
1649 </p>
1650 </li>
1651 <li>
1653 <code>css</code> suitable for cascading style sheets.
1654 </p>
1655 </li>
1656 <li>
1658 <code>dts</code> suitable for devicetree (DTS) files.
1659 </p>
1660 </li>
1661 <li>
1663 <code>elixir</code> suitable for source code in the Elixir language.
1664 </p>
1665 </li>
1666 <li>
1668 <code>fortran</code> suitable for source code in the Fortran language.
1669 </p>
1670 </li>
1671 <li>
1673 <code>fountain</code> suitable for Fountain documents.
1674 </p>
1675 </li>
1676 <li>
1678 <code>golang</code> suitable for source code in the Go language.
1679 </p>
1680 </li>
1681 <li>
1683 <code>html</code> suitable for HTML/XHTML documents.
1684 </p>
1685 </li>
1686 <li>
1688 <code>java</code> suitable for source code in the Java language.
1689 </p>
1690 </li>
1691 <li>
1693 <code>kotlin</code> suitable for source code in the Kotlin language.
1694 </p>
1695 </li>
1696 <li>
1698 <code>markdown</code> suitable for Markdown documents.
1699 </p>
1700 </li>
1701 <li>
1703 <code>matlab</code> suitable for source code in the MATLAB and Octave languages.
1704 </p>
1705 </li>
1706 <li>
1708 <code>objc</code> suitable for source code in the Objective-C language.
1709 </p>
1710 </li>
1711 <li>
1713 <code>pascal</code> suitable for source code in the Pascal/Delphi language.
1714 </p>
1715 </li>
1716 <li>
1718 <code>perl</code> suitable for source code in the Perl language.
1719 </p>
1720 </li>
1721 <li>
1723 <code>php</code> suitable for source code in the PHP language.
1724 </p>
1725 </li>
1726 <li>
1728 <code>python</code> suitable for source code in the Python language.
1729 </p>
1730 </li>
1731 <li>
1733 <code>ruby</code> suitable for source code in the Ruby language.
1734 </p>
1735 </li>
1736 <li>
1738 <code>rust</code> suitable for source code in the Rust language.
1739 </p>
1740 </li>
1741 <li>
1743 <code>scheme</code> suitable for source code in the Scheme language.
1744 </p>
1745 </li>
1746 <li>
1748 <code>tex</code> suitable for source code for LaTeX documents.
1749 </p>
1750 </li>
1751 </ul></div>
1752 </div>
1753 <div class="sect3">
1754 <h4 id="_customizing_word_diff">Customizing word diff</h4>
1755 <div class="paragraph"><p>You can customize the rules that <code>git diff --word-diff</code> uses to
1756 split words in a line, by specifying an appropriate regular expression
1757 in the "diff.*.wordRegex" configuration variable. For example, in TeX
1758 a backslash followed by a sequence of letters forms a command, but
1759 several such commands can be run together without intervening
1760 whitespace. To separate them, use a regular expression in your
1761 <code>$GIT_DIR/config</code> file (or <code>$HOME/.gitconfig</code> file) like this:</p></div>
1762 <div class="listingblock">
1763 <div class="content">
1764 <pre><code>[diff "tex"]
1765 wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"</code></pre>
1766 </div></div>
1767 <div class="paragraph"><p>A built-in pattern is provided for all languages listed in the
1768 previous section.</p></div>
1769 </div>
1770 <div class="sect3">
1771 <h4 id="_performing_text_diffs_of_binary_files">Performing text diffs of binary files</h4>
1772 <div class="paragraph"><p>Sometimes it is desirable to see the diff of a text-converted
1773 version of some binary files. For example, a word processor
1774 document can be converted to an ASCII text representation, and
1775 the diff of the text shown. Even though this conversion loses
1776 some information, the resulting diff is useful for human
1777 viewing (but cannot be applied directly).</p></div>
1778 <div class="paragraph"><p>The <code>textconv</code> config option is used to define a program for
1779 performing such a conversion. The program should take a single
1780 argument, the name of a file to convert, and produce the
1781 resulting text on stdout.</p></div>
1782 <div class="paragraph"><p>For example, to show the diff of the exif information of a
1783 file instead of the binary information (assuming you have the
1784 exif tool installed), add the following section to your
1785 <code>$GIT_DIR/config</code> file (or <code>$HOME/.gitconfig</code> file):</p></div>
1786 <div class="listingblock">
1787 <div class="content">
1788 <pre><code>[diff "jpg"]
1789 textconv = exif</code></pre>
1790 </div></div>
1791 <div class="admonitionblock">
1792 <table><tr>
1793 <td class="icon">
1794 <div class="title">Note</div>
1795 </td>
1796 <td class="content">The text conversion is generally a one-way conversion;
1797 in this example, we lose the actual image contents and focus
1798 just on the text data. This means that diffs generated by
1799 textconv are <em>not</em> suitable for applying. For this reason,
1800 only <code>git diff</code> and the <code>git log</code> family of commands (i.e.,
1801 log, whatchanged, show) will perform text conversion. <code>git
1802 format-patch</code> will never generate this output. If you want to
1803 send somebody a text-converted diff of a binary file (e.g.,
1804 because it quickly conveys the changes you have made), you
1805 should generate it separately and send it as a comment <em>in
1806 addition to</em> the usual binary diff that you might send.</td>
1807 </tr></table>
1808 </div>
1809 <div class="paragraph"><p>Because text conversion can be slow, especially when doing a
1810 large number of them with <code>git log -p</code>, Git provides a mechanism
1811 to cache the output and use it in future diffs. To enable
1812 caching, set the "cachetextconv" variable in your diff driver&#8217;s
1813 config. For example:</p></div>
1814 <div class="listingblock">
1815 <div class="content">
1816 <pre><code>[diff "jpg"]
1817 textconv = exif
1818 cachetextconv = true</code></pre>
1819 </div></div>
1820 <div class="paragraph"><p>This will cache the result of running "exif" on each blob
1821 indefinitely. If you change the textconv config variable for a
1822 diff driver, Git will automatically invalidate the cache entries
1823 and re-run the textconv filter. If you want to invalidate the
1824 cache manually (e.g., because your version of "exif" was updated
1825 and now produces better output), you can remove the cache
1826 manually with <code>git update-ref -d refs/notes/textconv/jpg</code> (where
1827 "jpg" is the name of the diff driver, as in the example above).</p></div>
1828 </div>
1829 <div class="sect3">
1830 <h4 id="_choosing_textconv_versus_external_diff">Choosing textconv versus external diff</h4>
1831 <div class="paragraph"><p>If you want to show differences between binary or specially-formatted
1832 blobs in your repository, you can choose to use either an external diff
1833 command, or to use textconv to convert them to a diff-able text format.
1834 Which method you choose depends on your exact situation.</p></div>
1835 <div class="paragraph"><p>The advantage of using an external diff command is flexibility. You are
1836 not bound to find line-oriented changes, nor is it necessary for the
1837 output to resemble unified diff. You are free to locate and report
1838 changes in the most appropriate way for your data format.</p></div>
1839 <div class="paragraph"><p>A textconv, by comparison, is much more limiting. You provide a
1840 transformation of the data into a line-oriented text format, and Git
1841 uses its regular diff tools to generate the output. There are several
1842 advantages to choosing this method:</p></div>
1843 <div class="olist arabic"><ol class="arabic">
1844 <li>
1846 Ease of use. It is often much simpler to write a binary to text
1847 transformation than it is to perform your own diff. In many cases,
1848 existing programs can be used as textconv filters (e.g., exif,
1849 odt2txt).
1850 </p>
1851 </li>
1852 <li>
1854 Git diff features. By performing only the transformation step
1855 yourself, you can still utilize many of Git&#8217;s diff features,
1856 including colorization, word-diff, and combined diffs for merges.
1857 </p>
1858 </li>
1859 <li>
1861 Caching. Textconv caching can speed up repeated diffs, such as those
1862 you might trigger by running <code>git log -p</code>.
1863 </p>
1864 </li>
1865 </ol></div>
1866 </div>
1867 <div class="sect3">
1868 <h4 id="_marking_files_as_binary">Marking files as binary</h4>
1869 <div class="paragraph"><p>Git usually guesses correctly whether a blob contains text or binary
1870 data by examining the beginning of the contents. However, sometimes you
1871 may want to override its decision, either because a blob contains binary
1872 data later in the file, or because the content, while technically
1873 composed of text characters, is opaque to a human reader. For example,
1874 many postscript files contain only ASCII characters, but produce noisy
1875 and meaningless diffs.</p></div>
1876 <div class="paragraph"><p>The simplest way to mark a file as binary is to unset the diff
1877 attribute in the <code>.gitattributes</code> file:</p></div>
1878 <div class="listingblock">
1879 <div class="content">
1880 <pre><code>*.ps -diff</code></pre>
1881 </div></div>
1882 <div class="paragraph"><p>This will cause Git to generate <code>Binary files differ</code> (or a binary
1883 patch, if binary patches are enabled) instead of a regular diff.</p></div>
1884 <div class="paragraph"><p>However, one may also want to specify other diff driver attributes. For
1885 example, you might want to use <code>textconv</code> to convert postscript files to
1886 an ASCII representation for human viewing, but otherwise treat them as
1887 binary files. You cannot specify both <code>-diff</code> and <code>diff=ps</code> attributes.
1888 The solution is to use the <code>diff.*.binary</code> config option:</p></div>
1889 <div class="listingblock">
1890 <div class="content">
1891 <pre><code>[diff "ps"]
1892 textconv = ps2ascii
1893 binary = true</code></pre>
1894 </div></div>
1895 </div>
1896 </div>
1897 <div class="sect2">
1898 <h3 id="_performing_a_three_way_merge">Performing a three-way merge</h3>
1899 <div class="sect3">
1900 <h4 id="_code_merge_code"><code>merge</code></h4>
1901 <div class="paragraph"><p>The attribute <code>merge</code> affects how three versions of a file are
1902 merged when a file-level merge is necessary during <code>git merge</code>,
1903 and other commands such as <code>git revert</code> and <code>git cherry-pick</code>.</p></div>
1904 <div class="dlist"><dl>
1905 <dt class="hdlist1">
1907 </dt>
1908 <dd>
1910 Built-in 3-way merge driver is used to merge the
1911 contents in a way similar to <em>merge</em> command of <code>RCS</code>
1912 suite. This is suitable for ordinary text files.
1913 </p>
1914 </dd>
1915 <dt class="hdlist1">
1916 Unset
1917 </dt>
1918 <dd>
1920 Take the version from the current branch as the
1921 tentative merge result, and declare that the merge has
1922 conflicts. This is suitable for binary files that do
1923 not have a well-defined merge semantics.
1924 </p>
1925 </dd>
1926 <dt class="hdlist1">
1927 Unspecified
1928 </dt>
1929 <dd>
1931 By default, this uses the same built-in 3-way merge
1932 driver as is the case when the <code>merge</code> attribute is set.
1933 However, the <code>merge.default</code> configuration variable can name
1934 different merge driver to be used with paths for which the
1935 <code>merge</code> attribute is unspecified.
1936 </p>
1937 </dd>
1938 <dt class="hdlist1">
1939 String
1940 </dt>
1941 <dd>
1943 3-way merge is performed using the specified custom
1944 merge driver. The built-in 3-way merge driver can be
1945 explicitly specified by asking for "text" driver; the
1946 built-in "take the current branch" driver can be
1947 requested with "binary".
1948 </p>
1949 </dd>
1950 </dl></div>
1951 </div>
1952 <div class="sect3">
1953 <h4 id="_built_in_merge_drivers">Built-in merge drivers</h4>
1954 <div class="paragraph"><p>There are a few built-in low-level merge drivers defined that
1955 can be asked for via the <code>merge</code> attribute.</p></div>
1956 <div class="dlist"><dl>
1957 <dt class="hdlist1">
1958 text
1959 </dt>
1960 <dd>
1962 Usual 3-way file level merge for text files. Conflicted
1963 regions are marked with conflict markers <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</code>,
1964 <code>=======</code> and <code>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</code>. The version from your branch
1965 appears before the <code>=======</code> marker, and the version
1966 from the merged branch appears after the <code>=======</code>
1967 marker.
1968 </p>
1969 </dd>
1970 <dt class="hdlist1">
1971 binary
1972 </dt>
1973 <dd>
1975 Keep the version from your branch in the work tree, but
1976 leave the path in the conflicted state for the user to
1977 sort out.
1978 </p>
1979 </dd>
1980 <dt class="hdlist1">
1981 union
1982 </dt>
1983 <dd>
1985 Run 3-way file level merge for text files, but take
1986 lines from both versions, instead of leaving conflict
1987 markers. This tends to leave the added lines in the
1988 resulting file in random order and the user should
1989 verify the result. Do not use this if you do not
1990 understand the implications.
1991 </p>
1992 </dd>
1993 </dl></div>
1994 </div>
1995 <div class="sect3">
1996 <h4 id="_defining_a_custom_merge_driver">Defining a custom merge driver</h4>
1997 <div class="paragraph"><p>The definition of a merge driver is done in the <code>.git/config</code>
1998 file, not in the <code>gitattributes</code> file, so strictly speaking this
1999 manual page is a wrong place to talk about it. However&#8230;</p></div>
2000 <div class="paragraph"><p>To define a custom merge driver <code>filfre</code>, add a section to your
2001 <code>$GIT_DIR/config</code> file (or <code>$HOME/.gitconfig</code> file) like this:</p></div>
2002 <div class="listingblock">
2003 <div class="content">
2004 <pre><code>[merge "filfre"]
2005 name = feel-free merge driver
2006 driver = filfre %O %A %B %L %P
2007 recursive = binary</code></pre>
2008 </div></div>
2009 <div class="paragraph"><p>The <code>merge.*.name</code> variable gives the driver a human-readable
2010 name.</p></div>
2011 <div class="paragraph"><p>The &#8216;merge.*.driver` variable&#8217;s value is used to construct a
2012 command to run to common ancestor&#8217;s version (<code>%O</code>), current
2013 version (<code>%A</code>) and the other branches&#8217; version (<code>%B</code>). These
2014 three tokens are replaced with the names of temporary files that
2015 hold the contents of these versions when the command line is
2016 built. Additionally, <code>%L</code> will be replaced with the conflict marker
2017 size (see below).</p></div>
2018 <div class="paragraph"><p>The merge driver is expected to leave the result of the merge in
2019 the file named with <code>%A</code> by overwriting it, and exit with zero
2020 status if it managed to merge them cleanly, or non-zero if there
2021 were conflicts. When the driver crashes (e.g. killed by SEGV),
2022 it is expected to exit with non-zero status that are higher than
2023 128, and in such a case, the merge results in a failure (which is
2024 different from producing a conflict).</p></div>
2025 <div class="paragraph"><p>The <code>merge.*.recursive</code> variable specifies what other merge
2026 driver to use when the merge driver is called for an internal
2027 merge between common ancestors, when there are more than one.
2028 When left unspecified, the driver itself is used for both
2029 internal merge and the final merge.</p></div>
2030 <div class="paragraph"><p>The merge driver can learn the pathname in which the merged result
2031 will be stored via placeholder <code>%P</code>. The conflict labels to be used
2032 for the common ancestor, local head and other head can be passed by
2033 using <em>%S</em>, <em>%X</em> and '%Y` respectively.</p></div>
2034 </div>
2035 <div class="sect3">
2036 <h4 id="_code_conflict_marker_size_code"><code>conflict-marker-size</code></h4>
2037 <div class="paragraph"><p>This attribute controls the length of conflict markers left in
2038 the work tree file during a conflicted merge. Only a positive
2039 integer has a meaningful effect.</p></div>
2040 <div class="paragraph"><p>For example, this line in <code>.gitattributes</code> can be used to tell the merge
2041 machinery to leave much longer (instead of the usual 7-character-long)
2042 conflict markers when merging the file <code>Documentation/git-merge.txt</code>
2043 results in a conflict.</p></div>
2044 <div class="listingblock">
2045 <div class="content">
2046 <pre><code>Documentation/git-merge.txt conflict-marker-size=32</code></pre>
2047 </div></div>
2048 </div>
2049 </div>
2050 <div class="sect2">
2051 <h3 id="_checking_whitespace_errors">Checking whitespace errors</h3>
2052 <div class="sect3">
2053 <h4 id="_code_whitespace_code"><code>whitespace</code></h4>
2054 <div class="paragraph"><p>The <code>core.whitespace</code> configuration variable allows you to define what
2055 <em>diff</em> and <em>apply</em> should consider whitespace errors for all paths in
2056 the project (See <a href="git-config.html">git-config(1)</a>). This attribute gives you finer
2057 control per path.</p></div>
2058 <div class="dlist"><dl>
2059 <dt class="hdlist1">
2061 </dt>
2062 <dd>
2064 Notice all types of potential whitespace errors known to Git.
2065 The tab width is taken from the value of the <code>core.whitespace</code>
2066 configuration variable.
2067 </p>
2068 </dd>
2069 <dt class="hdlist1">
2070 Unset
2071 </dt>
2072 <dd>
2074 Do not notice anything as error.
2075 </p>
2076 </dd>
2077 <dt class="hdlist1">
2078 Unspecified
2079 </dt>
2080 <dd>
2082 Use the value of the <code>core.whitespace</code> configuration variable to
2083 decide what to notice as error.
2084 </p>
2085 </dd>
2086 <dt class="hdlist1">
2087 String
2088 </dt>
2089 <dd>
2091 Specify a comma separated list of common whitespace problems to
2092 notice in the same format as the <code>core.whitespace</code> configuration
2093 variable.
2094 </p>
2095 </dd>
2096 </dl></div>
2097 </div>
2098 </div>
2099 <div class="sect2">
2100 <h3 id="_creating_an_archive">Creating an archive</h3>
2101 <div class="sect3">
2102 <h4 id="_code_export_ignore_code"><code>export-ignore</code></h4>
2103 <div class="paragraph"><p>Files and directories with the attribute <code>export-ignore</code> won&#8217;t be added to
2104 archive files.</p></div>
2105 </div>
2106 <div class="sect3">
2107 <h4 id="_code_export_subst_code"><code>export-subst</code></h4>
2108 <div class="paragraph"><p>If the attribute <code>export-subst</code> is set for a file then Git will expand
2109 several placeholders when adding this file to an archive. The
2110 expansion depends on the availability of a commit ID, i.e., if
2111 <a href="git-archive.html">git-archive(1)</a> has been given a tree instead of a commit or a
2112 tag then no replacement will be done. The placeholders are the same
2113 as those for the option <code>--pretty=format:</code> of <a href="git-log.html">git-log(1)</a>,
2114 except that they need to be wrapped like this: <code>$Format:PLACEHOLDERS$</code>
2115 in the file. E.g. the string <code>$Format:%H$</code> will be replaced by the
2116 commit hash. However, only one <code>%(describe)</code> placeholder is expanded
2117 per archive to avoid denial-of-service attacks.</p></div>
2118 </div>
2119 </div>
2120 <div class="sect2">
2121 <h3 id="_packing_objects">Packing objects</h3>
2122 <div class="sect3">
2123 <h4 id="_code_delta_code"><code>delta</code></h4>
2124 <div class="paragraph"><p>Delta compression will not be attempted for blobs for paths with the
2125 attribute <code>delta</code> set to false.</p></div>
2126 </div>
2127 </div>
2128 <div class="sect2">
2129 <h3 id="_viewing_files_in_gui_tools">Viewing files in GUI tools</h3>
2130 <div class="sect3">
2131 <h4 id="_code_encoding_code"><code>encoding</code></h4>
2132 <div class="paragraph"><p>The value of this attribute specifies the character encoding that should
2133 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
2134 display the contents of the relevant file. Note that due to performance
2135 considerations <a href="gitk.html">gitk(1)</a> does not use this attribute unless you
2136 manually enable per-file encodings in its options.</p></div>
2137 <div class="paragraph"><p>If this attribute is not set or has an invalid value, the value of the
2138 <code>gui.encoding</code> configuration variable is used instead
2139 (See <a href="git-config.html">git-config(1)</a>).</p></div>
2140 </div>
2141 </div>
2142 </div>
2143 </div>
2144 <div class="sect1">
2145 <h2 id="_using_macro_attributes">USING MACRO ATTRIBUTES</h2>
2146 <div class="sectionbody">
2147 <div class="paragraph"><p>You do not want any end-of-line conversions applied to, nor textual diffs
2148 produced for, any binary file you track. You would need to specify e.g.</p></div>
2149 <div class="listingblock">
2150 <div class="content">
2151 <pre><code>*.jpg -text -diff</code></pre>
2152 </div></div>
2153 <div class="paragraph"><p>but that may become cumbersome, when you have many attributes. Using
2154 macro attributes, you can define an attribute that, when set, also
2155 sets or unsets a number of other attributes at the same time. The
2156 system knows a built-in macro attribute, <code>binary</code>:</p></div>
2157 <div class="listingblock">
2158 <div class="content">
2159 <pre><code>*.jpg binary</code></pre>
2160 </div></div>
2161 <div class="paragraph"><p>Setting the "binary" attribute also unsets the "text" and "diff"
2162 attributes as above. Note that macro attributes can only be "Set",
2163 though setting one might have the effect of setting or unsetting other
2164 attributes or even returning other attributes to the "Unspecified"
2165 state.</p></div>
2166 </div>
2167 </div>
2168 <div class="sect1">
2169 <h2 id="_defining_macro_attributes">DEFINING MACRO ATTRIBUTES</h2>
2170 <div class="sectionbody">
2171 <div class="paragraph"><p>Custom macro attributes can be defined only in top-level gitattributes
2172 files (<code>$GIT_DIR/info/attributes</code>, the <code>.gitattributes</code> file at the
2173 top level of the working tree, or the global or system-wide
2174 gitattributes files), not in <code>.gitattributes</code> files in working tree
2175 subdirectories. The built-in macro attribute "binary" is equivalent
2176 to:</p></div>
2177 <div class="listingblock">
2178 <div class="content">
2179 <pre><code>[attr]binary -diff -merge -text</code></pre>
2180 </div></div>
2181 </div>
2182 </div>
2183 <div class="sect1">
2184 <h2 id="_notes">NOTES</h2>
2185 <div class="sectionbody">
2186 <div class="paragraph"><p>Git does not follow symbolic links when accessing a <code>.gitattributes</code>
2187 file in the working tree. This keeps behavior consistent when the file
2188 is accessed from the index or a tree versus from the filesystem.</p></div>
2189 </div>
2190 </div>
2191 <div class="sect1">
2192 <h2 id="_examples">EXAMPLES</h2>
2193 <div class="sectionbody">
2194 <div class="paragraph"><p>If you have these three <code>gitattributes</code> file:</p></div>
2195 <div class="listingblock">
2196 <div class="content">
2197 <pre><code>(in $GIT_DIR/info/attributes)
2199 a* foo !bar -baz
2201 (in .gitattributes)
2202 abc foo bar baz
2204 (in t/.gitattributes)
2205 ab* merge=filfre
2206 abc -foo -bar
2207 *.c frotz</code></pre>
2208 </div></div>
2209 <div class="paragraph"><p>the attributes given to path <code>t/abc</code> are computed as follows:</p></div>
2210 <div class="olist arabic"><ol class="arabic">
2211 <li>
2213 By examining <code>t/.gitattributes</code> (which is in the same
2214 directory as the path in question), Git finds that the first
2215 line matches. <code>merge</code> attribute is set. It also finds that
2216 the second line matches, and attributes <code>foo</code> and <code>bar</code>
2217 are unset.
2218 </p>
2219 </li>
2220 <li>
2222 Then it examines <code>.gitattributes</code> (which is in the parent
2223 directory), and finds that the first line matches, but
2224 <code>t/.gitattributes</code> file already decided how <code>merge</code>, <code>foo</code>
2225 and <code>bar</code> attributes should be given to this path, so it
2226 leaves <code>foo</code> and <code>bar</code> unset. Attribute <code>baz</code> is set.
2227 </p>
2228 </li>
2229 <li>
2231 Finally it examines <code>$GIT_DIR/info/attributes</code>. This file
2232 is used to override the in-tree settings. The first line is
2233 a match, and <code>foo</code> is set, <code>bar</code> is reverted to unspecified
2234 state, and <code>baz</code> is unset.
2235 </p>
2236 </li>
2237 </ol></div>
2238 <div class="paragraph"><p>As the result, the attributes assignment to <code>t/abc</code> becomes:</p></div>
2239 <div class="listingblock">
2240 <div class="content">
2241 <pre><code>foo set to true
2242 bar unspecified
2243 baz set to false
2244 merge set to string value "filfre"
2245 frotz unspecified</code></pre>
2246 </div></div>
2247 </div>
2248 </div>
2249 <div class="sect1">
2250 <h2 id="_see_also">SEE ALSO</h2>
2251 <div class="sectionbody">
2252 <div class="paragraph"><p><a href="git-check-attr.html">git-check-attr(1)</a>.</p></div>
2253 </div>
2254 </div>
2255 <div class="sect1">
2256 <h2 id="_git">GIT</h2>
2257 <div class="sectionbody">
2258 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
2259 </div>
2260 </div>
2261 </div>
2262 <div id="footnotes"><hr /></div>
2263 <div id="footer">
2264 <div id="footer-text">
2265 Last updated
2266 2024-02-02 14:30:49 PST
2267 </div>
2268 </div>
2269 </body>
2270 </html>