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">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8" />
6 <meta name=
"generator" content=
"AsciiDoc 8.4.5" />
7 <title>gitattributes(
5)
</title>
8 <style type=
"text/css">
10 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
12 border: 1px solid red;
17 margin: 1em 5% 1em 5%;
22 text-decoration: underline
;
42 h1
, h2
, h3
, h4
, h5
, h6
{
44 font-family: sans-serif
;
51 border-bottom: 2px solid silver
;
69 border: 1px solid silver
;
88 font-family: sans-serif
;
94 span#revnumber
, span#revdate
, span#revremark
{
95 font-family: sans-serif
;
99 font-family: sans-serif
;
101 border-top: 2px solid silver
;
107 padding-bottom: 0.5em;
111 padding-bottom: 0.5em;
116 margin-bottom: 1.5em;
118 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
119 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
120 div
.admonitionblock
{
122 margin-bottom: 1.5em;
124 div
.admonitionblock
{
126 margin-bottom: 2.5em;
129 div
.content
{ /* Block element content. */
133 /* Block element titles. */
134 div
.title
, caption
.title
{
136 font-family: sans-serif
;
140 margin-bottom: 0.5em;
146 td div
.title:first-child
{
149 div
.content div
.title:first-child
{
152 div
.content
+ div
.title
{
156 div
.sidebarblock
> div
.content
{
158 border: 1px solid silver
;
162 div
.listingblock
> div
.content
{
163 border: 1px solid silver
;
172 div
.quoteblock
> div
.attribution
{
181 div
.verseblock
> div
.content
{
184 div
.verseblock
> div
.attribution
{
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div
.verseblock
+ div
.attribution
{
193 div
.admonitionblock
.icon
{
197 text-decoration: underline
;
199 padding-right: 0.5em;
201 div
.admonitionblock td
.content
{
203 border-left: 2px solid silver
;
206 div
.exampleblock
> div
.content
{
207 border-left: 2px solid silver
;
211 div
.imageblock div
.content
{ padding-left: 0; }
212 span
.image img
{ border-style: none
; }
213 a
.image:visited
{ color: white
; }
217 margin-bottom: 0.8em;
230 list-style-position: outside
;
233 list-style-type: decimal
;
236 list-style-type: lower-alpha
;
239 list-style-type: upper-alpha
;
242 list-style-type: lower-roman
;
245 list-style-type: upper-roman
;
248 div
.compact ul
, div
.compact ol
,
249 div
.compact p
, div
.compact p
,
250 div
.compact div
, div
.compact div
{
252 margin-bottom: 0.1em;
255 div
.tableblock
> table
{
256 border: 3px solid
#527bbd;
259 font-family: sans-serif
;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div
.tableblock
> table
[frame
="void"] {
275 div
.tableblock
> table
[frame
="hsides"] {
276 border-left-style: none
;
277 border-right-style: none
;
279 div
.tableblock
> table
[frame
="vsides"] {
280 border-top-style: none
;
281 border-bottom-style: none
;
287 margin-bottom: 0.8em;
290 padding-bottom: 15px;
292 dt
.hdlist1
.strong
, td
.hdlist1
.strong
{
298 padding-right: 0.8em;
304 div
.hdlist
.compact tr
{
314 div#footer-badges
{ display: none
; }
319 font-family: sans-serif
;
323 margin-bottom: 0.1em;
326 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
342 /* Overrides for manpage documents */
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver
;
347 border-bottom: 2px solid silver
;
357 div#toc
{ display: none
; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div
.sidebar-content
{
364 border: 1px solid silver
;
367 div
.sidebar-title
, div
.image-title
{
369 font-family: sans-serif
;
372 margin-bottom: 0.5em;
375 div
.listingblock div
.content
{
376 border: 1px solid silver
;
381 div
.quoteblock-attribution
{
386 div
.verseblock-content
{
389 div
.verseblock-attribution
{
394 div
.exampleblock-content
{
395 border-left: 2px solid silver
;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc
a:visited
{ color: blue
; }
406 gitattributes(
5) Manual Page
409 <div class=
"sectionbody">
411 defining attributes per path
415 <h2 id=
"_synopsis">SYNOPSIS
</h2>
416 <div class=
"sectionbody">
417 <div class=
"paragraph"><p>$GIT_DIR/info/attributes, .gitattributes
</p></div>
419 <h2 id=
"_description">DESCRIPTION
</h2>
420 <div class=
"sectionbody">
421 <div class=
"paragraph"><p>A
<tt>gitattributes
</tt> file is a simple text file that gives
422 <tt>attributes
</tt> to pathnames.
</p></div>
423 <div class=
"paragraph"><p>Each line in
<tt>gitattributes
</tt> file is of form:
</p></div>
424 <div class=
"literalblock">
425 <div class=
"content">
426 <pre><tt>pattern attr1 attr2 ...
</tt></pre>
428 <div class=
"paragraph"><p>That is, a pattern followed by an attributes list,
429 separated by whitespaces. When the pattern matches the
430 path in question, the attributes listed on the line are given to
432 <div class=
"paragraph"><p>Each attribute can be in one of these states for a given path:
</p></div>
433 <div class=
"dlist"><dl>
439 The path has the attribute with special value
"true";
440 this is specified by listing only the name of the
441 attribute in the attribute list.
449 The path has the attribute with special value
"false";
450 this is specified by listing the name of the attribute
451 prefixed with a dash
<tt>-
</tt> in the attribute list.
459 The path has the attribute with specified string value;
460 this is specified by listing the name of the attribute
461 followed by an equal sign
<tt>=
</tt> and its value in the
470 No pattern matches the path, and nothing says if
471 the path has or does not have the attribute, the
472 attribute for the path is said to be Unspecified.
476 <div class=
"paragraph"><p>When more than one pattern matches the path, a later line
477 overrides an earlier line. This overriding is done per
478 attribute. The rules how the pattern matches paths are the
479 same as in
<tt>.gitignore
</tt> files; see
<a href=
"gitignore.html">gitignore(
5)
</a>.
</p></div>
480 <div class=
"paragraph"><p>When deciding what attributes are assigned to a path, git
481 consults
<tt>$GIT_DIR/info/attributes
</tt> file (which has the highest
482 precedence),
<tt>.gitattributes
</tt> file in the same directory as the
483 path in question, and its parent directories up to the toplevel of the
484 work tree (the further the directory that contains
<tt>.gitattributes
</tt>
485 is from the path in question, the lower its precedence). Finally
486 global and system-wide files are considered (they have the lowest
487 precedence).
</p></div>
488 <div class=
"paragraph"><p>If you wish to affect only a single repository (i.e., to assign
489 attributes to files that are particular to
490 one user
’s workflow for that repository), then
491 attributes should be placed in the
<tt>$GIT_DIR/info/attributes
</tt> file.
492 Attributes which should be version-controlled and distributed to other
493 repositories (i.e., attributes of interest to all users) should go into
494 <tt>.gitattributes
</tt> files. Attributes that should affect all repositories
495 for a single user should be placed in a file specified by the
496 <tt>core.attributesfile
</tt> configuration option (see
<a href=
"git-config.html">git-config(
1)
</a>).
497 Attributes for all users on a system should be placed in the
498 <tt>$(prefix)/etc/gitattributes
</tt> file.
</p></div>
499 <div class=
"paragraph"><p>Sometimes you would need to override an setting of an attribute
500 for a path to
<tt>Unspecified
</tt> state. This can be done by listing
501 the name of the attribute prefixed with an exclamation point
<tt>!
</tt>.
</p></div>
503 <h2 id=
"_effects">EFFECTS
</h2>
504 <div class=
"sectionbody">
505 <div class=
"paragraph"><p>Certain operations by git can be influenced by assigning
506 particular attributes to a path. Currently, the following
507 operations are attributes-aware.
</p></div>
508 <h3 id=
"_checking_out_and_checking_in">Checking-out and checking-in
</h3><div style=
"clear:left"></div>
509 <div class=
"paragraph"><p>These attributes affect how the contents stored in the
510 repository are copied to the working tree files when commands
511 such as
<em>git checkout
</em> and
<em>git merge
</em> run. They also affect how
512 git stores the contents you prepare in the working tree in the
513 repository upon
<em>git add
</em> and
<em>git commit
</em>.
</p></div>
514 <h4 id=
"_tt_text_tt"><tt>text
</tt></h4>
515 <div class=
"paragraph"><p>This attribute enables and controls end-of-line normalization. When a
516 text file is normalized, its line endings are converted to LF in the
517 repository. To control what line ending style is used in the working
518 directory, use the
<tt>eol
</tt> attribute for a single file and the
519 <tt>core.eol
</tt> configuration variable for all text files.
</p></div>
520 <div class=
"dlist"><dl>
526 Setting the
<tt>text
</tt> attribute on a path enables end-of-line
527 normalization and marks the path as a text file. End-of-line
528 conversion takes place without guessing the content type.
536 Unsetting the
<tt>text
</tt> attribute on a path tells git not to
537 attempt any end-of-line conversion upon checkin or checkout.
541 Set to string value
"auto"
545 When
<tt>text
</tt> is set to
"auto", the path is marked for automatic
546 end-of-line normalization. If git decides that the content is
547 text, its line endings are normalized to LF on checkin.
555 If the
<tt>text
</tt> attribute is unspecified, git uses the
556 <tt>core.autocrlf
</tt> configuration variable to determine if the
557 file should be converted.
561 <div class=
"paragraph"><p>Any other value causes git to act as if
<tt>text
</tt> has been left
562 unspecified.
</p></div>
563 <h4 id=
"_tt_eol_tt"><tt>eol
</tt></h4>
564 <div class=
"paragraph"><p>This attribute sets a specific line-ending style to be used in the
565 working directory. It enables end-of-line normalization without any
566 content checks, effectively setting the
<tt>text
</tt> attribute.
</p></div>
567 <div class=
"dlist"><dl>
569 Set to string value
"crlf"
573 This setting forces git to normalize line endings for this
574 file on checkin and convert them to CRLF when the file is
579 Set to string value
"lf"
583 This setting forces git to normalize line endings to LF on
584 checkin and prevents conversion to CRLF when the file is
589 <h4 id=
"_backwards_compatibility_with_tt_crlf_tt_attribute">Backwards compatibility with
<tt>crlf
</tt> attribute
</h4>
590 <div class=
"paragraph"><p>For backwards compatibility, the
<tt>crlf
</tt> attribute is interpreted as
592 <div class=
"listingblock">
593 <div class=
"content">
596 crlf=input eol=lf
</tt></pre>
598 <h4 id=
"_end_of_line_conversion">End-of-line conversion
</h4>
599 <div class=
"paragraph"><p>While git normally leaves file contents alone, it can be configured to
600 normalize line endings to LF in the repository and, optionally, to
601 convert them to CRLF when files are checked out.
</p></div>
602 <div class=
"paragraph"><p>Here is an example that will make git normalize .txt, .vcproj and .sh
603 files, ensure that .vcproj files have CRLF and .sh files have LF in
604 the working directory, and prevent .jpg files from being normalized
605 regardless of their content.
</p></div>
606 <div class=
"listingblock">
607 <div class=
"content">
611 *.jpg -text
</tt></pre>
613 <div class=
"paragraph"><p>Other source code management systems normalize all text files in their
614 repositories, and there are two ways to enable similar automatic
615 normalization in git.
</p></div>
616 <div class=
"paragraph"><p>If you simply want to have CRLF line endings in your working directory
617 regardless of the repository you are working with, you can set the
618 config variable
"core.autocrlf" without changing any attributes.
</p></div>
619 <div class=
"listingblock">
620 <div class=
"content">
622 autocrlf = true
</tt></pre>
624 <div class=
"paragraph"><p>This does not force normalization of all text files, but does ensure
625 that text files that you introduce to the repository have their line
626 endings normalized to LF when they are added, and that files that are
627 already normalized in the repository stay normalized.
</p></div>
628 <div class=
"paragraph"><p>If you want to interoperate with a source code management system that
629 enforces end-of-line normalization, or you simply want all text files
630 in your repository to be normalized, you should instead set the
<tt>text
</tt>
631 attribute to
"auto" for
<em>all
</em> files.
</p></div>
632 <div class=
"listingblock">
633 <div class=
"content">
634 <pre><tt>* text=auto
</tt></pre>
636 <div class=
"paragraph"><p>This ensures that all files that git considers to be text will have
637 normalized (LF) line endings in the repository. The
<tt>core.eol
</tt>
638 configuration variable controls which line endings git will use for
639 normalized files in your working directory; the default is to use the
640 native line ending for your platform, or CRLF if
<tt>core.autocrlf
</tt> is
642 <div class=
"admonitionblock">
645 <div class=
"title">Note
</div>
647 <td class=
"content">When
<tt>text=auto
</tt> normalization is enabled in an existing
648 repository, any text files containing CRLFs should be normalized. If
649 they are not they will be normalized the next time someone tries to
650 change them, causing unfortunate misattribution. From a clean working
654 <div class=
"listingblock">
655 <div class=
"content">
656 <pre><tt>$ echo
"* text=auto" >>.gitattributes
657 $ rm .git/index # Remove the index to force git to
658 $ git reset # re-scan the working directory
659 $ git status # Show files that will be normalized
661 $ git add .gitattributes
662 $ git commit -m
"Introduce end-of-line normalization"</tt></pre>
664 <div class=
"paragraph"><p>If any files that should not be normalized show up in
<em>git status
</em>,
665 unset their
<tt>text
</tt> attribute before running
<em>git add -u
</em>.
</p></div>
666 <div class=
"listingblock">
667 <div class=
"content">
668 <pre><tt>manual.pdf -text
</tt></pre>
670 <div class=
"paragraph"><p>Conversely, text files that git does not detect can have normalization
671 enabled manually.
</p></div>
672 <div class=
"listingblock">
673 <div class=
"content">
674 <pre><tt>weirdchars.txt text
</tt></pre>
676 <div class=
"paragraph"><p>If
<tt>core.safecrlf
</tt> is set to
"true" or
"warn", git verifies if
677 the conversion is reversible for the current setting of
678 <tt>core.autocrlf
</tt>. For
"true", git rejects irreversible
679 conversions; for
"warn", git only prints a warning but accepts
680 an irreversible conversion. The safety triggers to prevent such
681 a conversion done to the files in the work tree, but there are a
682 few exceptions. Even though
…</p></div>
683 <div class=
"ulist"><ul>
686 <em>git add
</em> itself does not touch the files in the work tree, the
687 next checkout would, so the safety triggers;
692 <em>git apply
</em> to update a text file with a patch does touch the files
693 in the work tree, but the operation is about text files and CRLF
694 conversion is about fixing the line ending inconsistencies, so the
695 safety does not trigger;
700 <em>git diff
</em> itself does not touch the files in the work tree, it is
701 often run to inspect the changes you intend to next
<em>git add
</em>. To
702 catch potential problems early, safety triggers.
706 <h4 id=
"_tt_ident_tt"><tt>ident
</tt></h4>
707 <div class=
"paragraph"><p>When the attribute
<tt>ident
</tt> is set for a path, git replaces
708 <tt>$Id$
</tt> in the blob object with
<tt>$Id:
</tt>, followed by the
709 40-character hexadecimal blob object name, followed by a dollar
710 sign
<tt>$
</tt> upon checkout. Any byte sequence that begins with
711 <tt>$Id:
</tt> and ends with
<tt>$
</tt> in the worktree file is replaced
712 with
<tt>$Id$
</tt> upon check-in.
</p></div>
713 <h4 id=
"_tt_filter_tt"><tt>filter
</tt></h4>
714 <div class=
"paragraph"><p>A
<tt>filter
</tt> attribute can be set to a string value that names a
715 filter driver specified in the configuration.
</p></div>
716 <div class=
"paragraph"><p>A filter driver consists of a
<tt>clean
</tt> command and a
<tt>smudge
</tt>
717 command, either of which can be left unspecified. Upon
718 checkout, when the
<tt>smudge
</tt> command is specified, the command is
719 fed the blob object from its standard input, and its standard
720 output is used to update the worktree file. Similarly, the
721 <tt>clean
</tt> command is used to convert the contents of worktree file
722 upon checkin.
</p></div>
723 <div class=
"paragraph"><p>A missing filter driver definition in the config is not an error
724 but makes the filter a no-op passthru.
</p></div>
725 <div class=
"paragraph"><p>The content filtering is done to massage the content into a
726 shape that is more convenient for the platform, filesystem, and
727 the user to use. The key phrase here is
"more convenient" and not
728 "turning something unusable into usable". In other words, the
729 intent is that if someone unsets the filter driver definition,
730 or does not have the appropriate filter program, the project
731 should still be usable.
</p></div>
732 <div class=
"paragraph"><p>For example, in .gitattributes, you would assign the
<tt>filter
</tt>
733 attribute for paths.
</p></div>
734 <div class=
"listingblock">
735 <div class=
"content">
736 <pre><tt>*.c filter=indent
</tt></pre>
738 <div class=
"paragraph"><p>Then you would define a
"filter.indent.clean" and
"filter.indent.smudge"
739 configuration in your .git/config to specify a pair of commands to
740 modify the contents of C programs when the source files are checked
741 in (
"clean" is run) and checked out (no change is made because the
742 command is
"cat").
</p></div>
743 <div class=
"listingblock">
744 <div class=
"content">
745 <pre><tt>[filter
"indent"]
747 smudge = cat
</tt></pre>
749 <div class=
"paragraph"><p>For best results,
<tt>clean
</tt> should not alter its output further if it is
750 run twice (
"clean→clean" should be equivalent to
"clean"), and
751 multiple
<tt>smudge
</tt> commands should not alter
<tt>clean
</tt>'s output
752 (
"smudge→smudge→clean" should be equivalent to
"clean"). See the
753 section on merging below.
</p></div>
754 <div class=
"paragraph"><p>The
"indent" filter is well-behaved in this regard: it will not modify
755 input that is already correctly indented. In this case, the lack of a
756 smudge filter means that the clean filter
<em>must
</em> accept its own output
757 without modifying it.
</p></div>
758 <div class=
"paragraph"><p>Sequence
"%f" on the filter command line is replaced with the name of
759 the file the filter is working on. A filter might use this in keyword
760 substitution. For example:
</p></div>
761 <div class=
"listingblock">
762 <div class=
"content">
763 <pre><tt>[filter
"p4"]
764 clean = git-p4-filter --clean %f
765 smudge = git-p4-filter --smudge %f
</tt></pre>
767 <h4 id=
"_interaction_between_checkin_checkout_attributes">Interaction between checkin/checkout attributes
</h4>
768 <div class=
"paragraph"><p>In the check-in codepath, the worktree file is first converted
769 with
<tt>filter
</tt> driver (if specified and corresponding driver
770 defined), then the result is processed with
<tt>ident
</tt> (if
771 specified), and then finally with
<tt>text
</tt> (again, if specified
772 and applicable).
</p></div>
773 <div class=
"paragraph"><p>In the check-out codepath, the blob content is first converted
774 with
<tt>text
</tt>, and then
<tt>ident
</tt> and fed to
<tt>filter
</tt>.
</p></div>
775 <h4 id=
"_merging_branches_with_differing_checkin_checkout_attributes">Merging branches with differing checkin/checkout attributes
</h4>
776 <div class=
"paragraph"><p>If you have added attributes to a file that cause the canonical
777 repository format for that file to change, such as adding a
778 clean/smudge filter or text/eol/ident attributes, merging anything
779 where the attribute is not in place would normally cause merge
781 <div class=
"paragraph"><p>To prevent these unnecessary merge conflicts, git can be told to run a
782 virtual check-out and check-in of all three stages of a file when
783 resolving a three-way merge by setting the
<tt>merge.renormalize
</tt>
784 configuration variable. This prevents changes caused by check-in
785 conversion from causing spurious merge conflicts when a converted file
786 is merged with an unconverted file.
</p></div>
787 <div class=
"paragraph"><p>As long as a
"smudge→clean" results in the same output as a
"clean"
788 even on files that are already smudged, this strategy will
789 automatically resolve all filter-related conflicts. Filters that do
790 not act in this way may cause additional merge conflicts that must be
791 resolved manually.
</p></div>
792 <h3 id=
"_generating_diff_text">Generating diff text
</h3><div style=
"clear:left"></div>
793 <h4 id=
"_tt_diff_tt"><tt>diff
</tt></h4>
794 <div class=
"paragraph"><p>The attribute
<tt>diff
</tt> affects how
<em>git
</em> generates diffs for particular
795 files. It can tell git whether to generate a textual patch for the path
796 or to treat the path as a binary file. It can also affect what line is
797 shown on the hunk header
<tt>@@ -k,l +n,m @@
</tt> line, tell git to use an
798 external command to generate the diff, or ask git to convert binary
799 files to a text format before generating the diff.
</p></div>
800 <div class=
"dlist"><dl>
806 A path to which the
<tt>diff
</tt> attribute is set is treated
807 as text, even when they contain byte values that
808 normally never appear in text files, such as NUL.
816 A path to which the
<tt>diff
</tt> attribute is unset will
817 generate
<tt>Binary files differ
</tt> (or a binary patch, if
818 binary patches are enabled).
826 A path to which the
<tt>diff
</tt> attribute is unspecified
827 first gets its contents inspected, and if it looks like
828 text, it is treated as text. Otherwise it would
829 generate
<tt>Binary files differ
</tt>.
837 Diff is shown using the specified diff driver. Each driver may
838 specify one or more options, as described in the following
839 section. The options for the diff driver
"foo" are defined
840 by the configuration variables in the
"diff.foo" section of the
845 <h4 id=
"_defining_an_external_diff_driver">Defining an external diff driver
</h4>
846 <div class=
"paragraph"><p>The definition of a diff driver is done in
<tt>gitconfig
</tt>, not
847 <tt>gitattributes
</tt> file, so strictly speaking this manual page is a
848 wrong place to talk about it. However
…</p></div>
849 <div class=
"paragraph"><p>To define an external diff driver
<tt>jcdiff
</tt>, add a section to your
850 <tt>$GIT_DIR/config
</tt> file (or
<tt>$HOME/.gitconfig
</tt> file) like this:
</p></div>
851 <div class=
"listingblock">
852 <div class=
"content">
853 <pre><tt>[diff
"jcdiff"]
854 command = j-c-diff
</tt></pre>
856 <div class=
"paragraph"><p>When git needs to show you a diff for the path with
<tt>diff
</tt>
857 attribute set to
<tt>jcdiff
</tt>, it calls the command you specified
858 with the above configuration, i.e.
<tt>j-c-diff
</tt>, with
7
859 parameters, just like
<tt>GIT_EXTERNAL_DIFF
</tt> program is called.
860 See
<a href=
"git.html">git(
1)
</a> for details.
</p></div>
861 <h4 id=
"_defining_a_custom_hunk_header">Defining a custom hunk-header
</h4>
862 <div class=
"paragraph"><p>Each group of changes (called a
"hunk") in the textual diff output
863 is prefixed with a line of the form:
</p></div>
864 <div class=
"literalblock">
865 <div class=
"content">
866 <pre><tt>@@ -k,l +n,m @@ TEXT
</tt></pre>
868 <div class=
"paragraph"><p>This is called a
<em>hunk header
</em>. The
"TEXT" portion is by default a line
869 that begins with an alphabet, an underscore or a dollar sign; this
870 matches what GNU
<em>diff -p
</em> output uses. This default selection however
871 is not suited for some contents, and you can use a customized pattern
872 to make a selection.
</p></div>
873 <div class=
"paragraph"><p>First, in .gitattributes, you would assign the
<tt>diff
</tt> attribute
875 <div class=
"listingblock">
876 <div class=
"content">
877 <pre><tt>*.tex diff=tex
</tt></pre>
879 <div class=
"paragraph"><p>Then, you would define a
"diff.tex.xfuncname" configuration to
880 specify a regular expression that matches a line that you would
881 want to appear as the hunk header
"TEXT". Add a section to your
882 <tt>$GIT_DIR/config
</tt> file (or
<tt>$HOME/.gitconfig
</tt> file) like this:
</p></div>
883 <div class=
"listingblock">
884 <div class=
"content">
885 <pre><tt>[diff
"tex"]
886 xfuncname =
"^(\\\\(sub)*section\\{.*)$"</tt></pre>
888 <div class=
"paragraph"><p>Note. A single level of backslashes are eaten by the
889 configuration file parser, so you would need to double the
890 backslashes; the pattern above picks a line that begins with a
891 backslash, and zero or more occurrences of
<tt>sub
</tt> followed by
892 <tt>section
</tt> followed by open brace, to the end of line.
</p></div>
893 <div class=
"paragraph"><p>There are a few built-in patterns to make this easier, and
<tt>tex
</tt>
894 is one of them, so you do not have to write the above in your
895 configuration file (you still need to enable this with the
896 attribute mechanism, via
<tt>.gitattributes
</tt>). The following built in
897 patterns are available:
</p></div>
898 <div class=
"ulist"><ul>
901 <tt>bibtex
</tt> suitable for files with BibTeX coded references.
906 <tt>cpp
</tt> suitable for source code in the C and C++ languages.
911 <tt>csharp
</tt> suitable for source code in the C# language.
916 <tt>fortran
</tt> suitable for source code in the Fortran language.
921 <tt>html
</tt> suitable for HTML/XHTML documents.
926 <tt>java
</tt> suitable for source code in the Java language.
931 <tt>objc
</tt> suitable for source code in the Objective-C language.
936 <tt>pascal
</tt> suitable for source code in the Pascal/Delphi language.
941 <tt>perl
</tt> suitable for source code in the Perl language.
946 <tt>php
</tt> suitable for source code in the PHP language.
951 <tt>python
</tt> suitable for source code in the Python language.
956 <tt>ruby
</tt> suitable for source code in the Ruby language.
961 <tt>tex
</tt> suitable for source code for LaTeX documents.
965 <h4 id=
"_customizing_word_diff">Customizing word diff
</h4>
966 <div class=
"paragraph"><p>You can customize the rules that
<tt>git diff --word-diff
</tt> uses to
967 split words in a line, by specifying an appropriate regular expression
968 in the
"diff.*.wordRegex" configuration variable. For example, in TeX
969 a backslash followed by a sequence of letters forms a command, but
970 several such commands can be run together without intervening
971 whitespace. To separate them, use a regular expression in your
972 <tt>$GIT_DIR/config
</tt> file (or
<tt>$HOME/.gitconfig
</tt> file) like this:
</p></div>
973 <div class=
"listingblock">
974 <div class=
"content">
975 <pre><tt>[diff
"tex"]
976 wordRegex =
"\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"</tt></pre>
978 <div class=
"paragraph"><p>A built-in pattern is provided for all languages listed in the
979 previous section.
</p></div>
980 <h4 id=
"_performing_text_diffs_of_binary_files">Performing text diffs of binary files
</h4>
981 <div class=
"paragraph"><p>Sometimes it is desirable to see the diff of a text-converted
982 version of some binary files. For example, a word processor
983 document can be converted to an ASCII text representation, and
984 the diff of the text shown. Even though this conversion loses
985 some information, the resulting diff is useful for human
986 viewing (but cannot be applied directly).
</p></div>
987 <div class=
"paragraph"><p>The
<tt>textconv
</tt> config option is used to define a program for
988 performing such a conversion. The program should take a single
989 argument, the name of a file to convert, and produce the
990 resulting text on stdout.
</p></div>
991 <div class=
"paragraph"><p>For example, to show the diff of the exif information of a
992 file instead of the binary information (assuming you have the
993 exif tool installed), add the following section to your
994 <tt>$GIT_DIR/config
</tt> file (or
<tt>$HOME/.gitconfig
</tt> file):
</p></div>
995 <div class=
"listingblock">
996 <div class=
"content">
997 <pre><tt>[diff
"jpg"]
998 textconv = exif
</tt></pre>
1000 <div class=
"admonitionblock">
1003 <div class=
"title">Note
</div>
1005 <td class=
"content">The text conversion is generally a one-way conversion;
1006 in this example, we lose the actual image contents and focus
1007 just on the text data. This means that diffs generated by
1008 textconv are
<em>not
</em> suitable for applying. For this reason,
1009 only
<tt>git diff
</tt> and the
<tt>git log
</tt> family of commands (i.e.,
1010 log, whatchanged, show) will perform text conversion.
<tt>git
1011 format-patch
</tt> will never generate this output. If you want to
1012 send somebody a text-converted diff of a binary file (e.g.,
1013 because it quickly conveys the changes you have made), you
1014 should generate it separately and send it as a comment
<em>in
1015 addition to
</em> the usual binary diff that you might send.
</td>
1018 <div class=
"paragraph"><p>Because text conversion can be slow, especially when doing a
1019 large number of them with
<tt>git log -p
</tt>, git provides a mechanism
1020 to cache the output and use it in future diffs. To enable
1021 caching, set the
"cachetextconv" variable in your diff driver
’s
1022 config. For example:
</p></div>
1023 <div class=
"listingblock">
1024 <div class=
"content">
1025 <pre><tt>[diff
"jpg"]
1027 cachetextconv = true
</tt></pre>
1029 <div class=
"paragraph"><p>This will cache the result of running
"exif" on each blob
1030 indefinitely. If you change the textconv config variable for a
1031 diff driver, git will automatically invalidate the cache entries
1032 and re-run the textconv filter. If you want to invalidate the
1033 cache manually (e.g., because your version of
"exif" was updated
1034 and now produces better output), you can remove the cache
1035 manually with
<tt>git update-ref -d refs/notes/textconv/jpg
</tt> (where
1036 "jpg" is the name of the diff driver, as in the example above).
</p></div>
1037 <h4 id=
"_choosing_textconv_versus_external_diff">Choosing textconv versus external diff
</h4>
1038 <div class=
"paragraph"><p>If you want to show differences between binary or specially-formatted
1039 blobs in your repository, you can choose to use either an external diff
1040 command, or to use textconv to convert them to a diff-able text format.
1041 Which method you choose depends on your exact situation.
</p></div>
1042 <div class=
"paragraph"><p>The advantage of using an external diff command is flexibility. You are
1043 not bound to find line-oriented changes, nor is it necessary for the
1044 output to resemble unified diff. You are free to locate and report
1045 changes in the most appropriate way for your data format.
</p></div>
1046 <div class=
"paragraph"><p>A textconv, by comparison, is much more limiting. You provide a
1047 transformation of the data into a line-oriented text format, and git
1048 uses its regular diff tools to generate the output. There are several
1049 advantages to choosing this method:
</p></div>
1050 <div class=
"olist arabic"><ol class=
"arabic">
1053 Ease of use. It is often much simpler to write a binary to text
1054 transformation than it is to perform your own diff. In many cases,
1055 existing programs can be used as textconv filters (e.g., exif,
1061 Git diff features. By performing only the transformation step
1062 yourself, you can still utilize many of git
’s diff features,
1063 including colorization, word-diff, and combined diffs for merges.
1068 Caching. Textconv caching can speed up repeated diffs, such as those
1069 you might trigger by running
<tt>git log -p
</tt>.
1073 <h4 id=
"_marking_files_as_binary">Marking files as binary
</h4>
1074 <div class=
"paragraph"><p>Git usually guesses correctly whether a blob contains text or binary
1075 data by examining the beginning of the contents. However, sometimes you
1076 may want to override its decision, either because a blob contains binary
1077 data later in the file, or because the content, while technically
1078 composed of text characters, is opaque to a human reader. For example,
1079 many postscript files contain only ascii characters, but produce noisy
1080 and meaningless diffs.
</p></div>
1081 <div class=
"paragraph"><p>The simplest way to mark a file as binary is to unset the diff
1082 attribute in the
<tt>.gitattributes
</tt> file:
</p></div>
1083 <div class=
"listingblock">
1084 <div class=
"content">
1085 <pre><tt>*.ps -diff
</tt></pre>
1087 <div class=
"paragraph"><p>This will cause git to generate
<tt>Binary files differ
</tt> (or a binary
1088 patch, if binary patches are enabled) instead of a regular diff.
</p></div>
1089 <div class=
"paragraph"><p>However, one may also want to specify other diff driver attributes. For
1090 example, you might want to use
<tt>textconv
</tt> to convert postscript files to
1091 an ascii representation for human viewing, but otherwise treat them as
1092 binary files. You cannot specify both
<tt>-diff
</tt> and
<tt>diff=ps
</tt> attributes.
1093 The solution is to use the
<tt>diff.*.binary
</tt> config option:
</p></div>
1094 <div class=
"listingblock">
1095 <div class=
"content">
1096 <pre><tt>[diff
"ps"]
1098 binary = true
</tt></pre>
1100 <h3 id=
"_performing_a_three_way_merge">Performing a three-way merge
</h3><div style=
"clear:left"></div>
1101 <h4 id=
"_tt_merge_tt"><tt>merge
</tt></h4>
1102 <div class=
"paragraph"><p>The attribute
<tt>merge
</tt> affects how three versions of a file are
1103 merged when a file-level merge is necessary during
<tt>git merge
</tt>,
1104 and other commands such as
<tt>git revert
</tt> and
<tt>git cherry-pick
</tt>.
</p></div>
1105 <div class=
"dlist"><dl>
1106 <dt class=
"hdlist1">
1111 Built-in
3-way merge driver is used to merge the
1112 contents in a way similar to
<em>merge
</em> command of
<tt>RCS
</tt>
1113 suite. This is suitable for ordinary text files.
1116 <dt class=
"hdlist1">
1121 Take the version from the current branch as the
1122 tentative merge result, and declare that the merge has
1123 conflicts. This is suitable for binary files that do
1124 not have a well-defined merge semantics.
1127 <dt class=
"hdlist1">
1132 By default, this uses the same built-in
3-way merge
1133 driver as is the case when the
<tt>merge
</tt> attribute is set.
1134 However, the
<tt>merge.default
</tt> configuration variable can name
1135 different merge driver to be used with paths for which the
1136 <tt>merge
</tt> attribute is unspecified.
1139 <dt class=
"hdlist1">
1144 3-way merge is performed using the specified custom
1145 merge driver. The built-in
3-way merge driver can be
1146 explicitly specified by asking for
"text" driver; the
1147 built-in
"take the current branch" driver can be
1148 requested with
"binary".
1152 <h4 id=
"_built_in_merge_drivers">Built-in merge drivers
</h4>
1153 <div class=
"paragraph"><p>There are a few built-in low-level merge drivers defined that
1154 can be asked for via the
<tt>merge
</tt> attribute.
</p></div>
1155 <div class=
"dlist"><dl>
1156 <dt class=
"hdlist1">
1161 Usual
3-way file level merge for text files. Conflicted
1162 regions are marked with conflict markers
<tt><<<<<<<</tt>,
1163 <tt>=======
</tt> and
<tt>>>>>>>></tt>. The version from your branch
1164 appears before the
<tt>=======
</tt> marker, and the version
1165 from the merged branch appears after the
<tt>=======
</tt>
1169 <dt class=
"hdlist1">
1174 Keep the version from your branch in the work tree, but
1175 leave the path in the conflicted state for the user to
1179 <dt class=
"hdlist1">
1184 Run
3-way file level merge for text files, but take
1185 lines from both versions, instead of leaving conflict
1186 markers. This tends to leave the added lines in the
1187 resulting file in random order and the user should
1188 verify the result. Do not use this if you do not
1189 understand the implications.
1193 <h4 id=
"_defining_a_custom_merge_driver">Defining a custom merge driver
</h4>
1194 <div class=
"paragraph"><p>The definition of a merge driver is done in the
<tt>.git/config
</tt>
1195 file, not in the
<tt>gitattributes
</tt> file, so strictly speaking this
1196 manual page is a wrong place to talk about it. However
…</p></div>
1197 <div class=
"paragraph"><p>To define a custom merge driver
<tt>filfre
</tt>, add a section to your
1198 <tt>$GIT_DIR/config
</tt> file (or
<tt>$HOME/.gitconfig
</tt> file) like this:
</p></div>
1199 <div class=
"listingblock">
1200 <div class=
"content">
1201 <pre><tt>[merge
"filfre"]
1202 name = feel-free merge driver
1203 driver = filfre %O %A %B
1204 recursive = binary
</tt></pre>
1206 <div class=
"paragraph"><p>The
<tt>merge.*.name
</tt> variable gives the driver a human-readable
1208 <div class=
"paragraph"><p>The
‘merge.*.driver` variable
’s value is used to construct a
1209 command to run to merge ancestor
’s version (
<tt>%O
</tt>), current
1210 version (
<tt>%A
</tt>) and the other branches
’ version (
<tt>%B
</tt>). These
1211 three tokens are replaced with the names of temporary files that
1212 hold the contents of these versions when the command line is
1213 built. Additionally, %L will be replaced with the conflict marker
1214 size (see below).
</p></div>
1215 <div class=
"paragraph"><p>The merge driver is expected to leave the result of the merge in
1216 the file named with
<tt>%A
</tt> by overwriting it, and exit with zero
1217 status if it managed to merge them cleanly, or non-zero if there
1218 were conflicts.
</p></div>
1219 <div class=
"paragraph"><p>The
<tt>merge.*.recursive
</tt> variable specifies what other merge
1220 driver to use when the merge driver is called for an internal
1221 merge between common ancestors, when there are more than one.
1222 When left unspecified, the driver itself is used for both
1223 internal merge and the final merge.
</p></div>
1224 <h4 id=
"_tt_conflict_marker_size_tt"><tt>conflict-marker-size
</tt></h4>
1225 <div class=
"paragraph"><p>This attribute controls the length of conflict markers left in
1226 the work tree file during a conflicted merge. Only setting to
1227 the value to a positive integer has any meaningful effect.
</p></div>
1228 <div class=
"paragraph"><p>For example, this line in
<tt>.gitattributes
</tt> can be used to tell the merge
1229 machinery to leave much longer (instead of the usual
7-character-long)
1230 conflict markers when merging the file
<tt>Documentation/git-merge.txt
</tt>
1231 results in a conflict.
</p></div>
1232 <div class=
"listingblock">
1233 <div class=
"content">
1234 <pre><tt>Documentation/git-merge.txt conflict-marker-size=
32</tt></pre>
1236 <h3 id=
"_checking_whitespace_errors">Checking whitespace errors
</h3><div style=
"clear:left"></div>
1237 <h4 id=
"_tt_whitespace_tt"><tt>whitespace
</tt></h4>
1238 <div class=
"paragraph"><p>The
<tt>core.whitespace
</tt> configuration variable allows you to define what
1239 <em>diff
</em> and
<em>apply
</em> should consider whitespace errors for all paths in
1240 the project (See
<a href=
"git-config.html">git-config(
1)
</a>). This attribute gives you finer
1241 control per path.
</p></div>
1242 <div class=
"dlist"><dl>
1243 <dt class=
"hdlist1">
1248 Notice all types of potential whitespace errors known to git.
1249 The tab width is taken from the value of the
<tt>core.whitespace
</tt>
1250 configuration variable.
1253 <dt class=
"hdlist1">
1258 Do not notice anything as error.
1261 <dt class=
"hdlist1">
1266 Use the value of the
<tt>core.whitespace
</tt> configuration variable to
1267 decide what to notice as error.
1270 <dt class=
"hdlist1">
1275 Specify a comma separate list of common whitespace problems to
1276 notice in the same format as the
<tt>core.whitespace
</tt> configuration
1281 <h3 id=
"_creating_an_archive">Creating an archive
</h3><div style=
"clear:left"></div>
1282 <h4 id=
"_tt_export_ignore_tt"><tt>export-ignore
</tt></h4>
1283 <div class=
"paragraph"><p>Files and directories with the attribute
<tt>export-ignore
</tt> won
’t be added to
1284 archive files.
</p></div>
1285 <h4 id=
"_tt_export_subst_tt"><tt>export-subst
</tt></h4>
1286 <div class=
"paragraph"><p>If the attribute
<tt>export-subst
</tt> is set for a file then git will expand
1287 several placeholders when adding this file to an archive. The
1288 expansion depends on the availability of a commit ID, i.e., if
1289 <a href=
"git-archive.html">git-archive(
1)
</a> has been given a tree instead of a commit or a
1290 tag then no replacement will be done. The placeholders are the same
1291 as those for the option
<tt>--pretty=format:
</tt> of
<a href=
"git-log.html">git-log(
1)
</a>,
1292 except that they need to be wrapped like this:
<tt>$Format:PLACEHOLDERS$
</tt>
1293 in the file. E.g. the string
<tt>$Format:%H$
</tt> will be replaced by the
1294 commit hash.
</p></div>
1295 <h3 id=
"_packing_objects">Packing objects
</h3><div style=
"clear:left"></div>
1296 <h4 id=
"_tt_delta_tt"><tt>delta
</tt></h4>
1297 <div class=
"paragraph"><p>Delta compression will not be attempted for blobs for paths with the
1298 attribute
<tt>delta
</tt> set to false.
</p></div>
1299 <h3 id=
"_viewing_files_in_gui_tools">Viewing files in GUI tools
</h3><div style=
"clear:left"></div>
1300 <h4 id=
"_tt_encoding_tt"><tt>encoding
</tt></h4>
1301 <div class=
"paragraph"><p>The value of this attribute specifies the character encoding that should
1302 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
1303 display the contents of the relevant file. Note that due to performance
1304 considerations
<a href=
"gitk.html">gitk(
1)
</a> does not use this attribute unless you
1305 manually enable per-file encodings in its options.
</p></div>
1306 <div class=
"paragraph"><p>If this attribute is not set or has an invalid value, the value of the
1307 <tt>gui.encoding
</tt> configuration variable is used instead
1308 (See
<a href=
"git-config.html">git-config(
1)
</a>).
</p></div>
1310 <h2 id=
"_using_macro_attributes">USING MACRO ATTRIBUTES
</h2>
1311 <div class=
"sectionbody">
1312 <div class=
"paragraph"><p>You do not want any end-of-line conversions applied to, nor textual diffs
1313 produced for, any binary file you track. You would need to specify e.g.
</p></div>
1314 <div class=
"listingblock">
1315 <div class=
"content">
1316 <pre><tt>*.jpg -text -diff
</tt></pre>
1318 <div class=
"paragraph"><p>but that may become cumbersome, when you have many attributes. Using
1319 macro attributes, you can define an attribute that, when set, also
1320 sets or unsets a number of other attributes at the same time. The
1321 system knows a built-in macro attribute,
<tt>binary
</tt>:
</p></div>
1322 <div class=
"listingblock">
1323 <div class=
"content">
1324 <pre><tt>*.jpg binary
</tt></pre>
1326 <div class=
"paragraph"><p>Setting the
"binary" attribute also unsets the
"text" and
"diff"
1327 attributes as above. Note that macro attributes can only be
"Set",
1328 though setting one might have the effect of setting or unsetting other
1329 attributes or even returning other attributes to the
"Unspecified"
1332 <h2 id=
"_defining_macro_attributes">DEFINING MACRO ATTRIBUTES
</h2>
1333 <div class=
"sectionbody">
1334 <div class=
"paragraph"><p>Custom macro attributes can be defined only in the
<tt>.gitattributes
</tt>
1335 file at the toplevel (i.e. not in any subdirectory). The built-in
1336 macro attribute
"binary" is equivalent to:
</p></div>
1337 <div class=
"listingblock">
1338 <div class=
"content">
1339 <pre><tt>[attr]binary -diff -text
</tt></pre>
1342 <h2 id=
"_example">EXAMPLE
</h2>
1343 <div class=
"sectionbody">
1344 <div class=
"paragraph"><p>If you have these three
<tt>gitattributes
</tt> file:
</p></div>
1345 <div class=
"listingblock">
1346 <div class=
"content">
1347 <pre><tt>(in $GIT_DIR/info/attributes)
1354 (in t/.gitattributes)
1357 *.c frotz
</tt></pre>
1359 <div class=
"paragraph"><p>the attributes given to path
<tt>t/abc
</tt> are computed as follows:
</p></div>
1360 <div class=
"olist arabic"><ol class=
"arabic">
1363 By examining
<tt>t/.gitattributes
</tt> (which is in the same
1364 directory as the path in question), git finds that the first
1365 line matches.
<tt>merge
</tt> attribute is set. It also finds that
1366 the second line matches, and attributes
<tt>foo
</tt> and
<tt>bar
</tt>
1372 Then it examines
<tt>.gitattributes
</tt> (which is in the parent
1373 directory), and finds that the first line matches, but
1374 <tt>t/.gitattributes
</tt> file already decided how
<tt>merge
</tt>,
<tt>foo
</tt>
1375 and
<tt>bar
</tt> attributes should be given to this path, so it
1376 leaves
<tt>foo
</tt> and
<tt>bar
</tt> unset. Attribute
<tt>baz
</tt> is set.
1381 Finally it examines
<tt>$GIT_DIR/info/attributes
</tt>. This file
1382 is used to override the in-tree settings. The first line is
1383 a match, and
<tt>foo
</tt> is set,
<tt>bar
</tt> is reverted to unspecified
1384 state, and
<tt>baz
</tt> is unset.
1388 <div class=
"paragraph"><p>As the result, the attributes assignment to
<tt>t/abc
</tt> becomes:
</p></div>
1389 <div class=
"listingblock">
1390 <div class=
"content">
1391 <pre><tt>foo set to true
1394 merge set to string value
"filfre"
1395 frotz unspecified
</tt></pre>
1398 <h2 id=
"_git">GIT
</h2>
1399 <div class=
"sectionbody">
1400 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
1403 <div id=
"footer-text">
1404 Last updated
2011-
08-
04 00:
21:
28 UTC