1GITATTRIBUTES(5)                  Git Manual                  GITATTRIBUTES(5)
2
3
4

NAME

6       gitattributes - Defining attributes per path
7

SYNOPSIS

9       $GIT_DIR/info/attributes, .gitattributes
10

DESCRIPTION

12       A gitattributes file is a simple text file that gives attributes to
13       pathnames.
14
15       Each line in gitattributes file is of form:
16
17           pattern attr1 attr2 ...
18
19       That is, a pattern followed by an attributes list, separated by
20       whitespaces. Leading and trailing whitespaces are ignored. Lines that
21       begin with # are ignored. Patterns that begin with a double quote are
22       quoted in C style. When the pattern matches the path in question, the
23       attributes listed on the line are given to the path.
24
25       Each attribute can be in one of these states for a given path:
26
27       Set
28           The path has the attribute with special value "true"; this is
29           specified by listing only the name of the attribute in the
30           attribute list.
31
32       Unset
33           The path has the attribute with special value "false"; this is
34           specified by listing the name of the attribute prefixed with a dash
35           - in the attribute list.
36
37       Set to a value
38           The path has the attribute with specified string value; this is
39           specified by listing the name of the attribute followed by an equal
40           sign = and its value in the attribute list.
41
42       Unspecified
43           No pattern matches the path, and nothing says if the path has or
44           does not have the attribute, the attribute for the path is said to
45           be Unspecified.
46
47       When more than one pattern matches the path, a later line overrides an
48       earlier line. This overriding is done per attribute.
49
50       The rules by which the pattern matches paths are the same as in
51       .gitignore files (see gitignore(5)), with a few exceptions:
52
53       ·   negative patterns are forbidden
54
55       ·   patterns that match a directory do not recursively match paths
56           inside that directory (so using the trailing-slash path/ syntax is
57           pointless in an attributes file; use path/** instead)
58
59       When deciding what attributes are assigned to a path, Git consults
60       $GIT_DIR/info/attributes file (which has the highest precedence),
61       .gitattributes file in the same directory as the path in question, and
62       its parent directories up to the toplevel of the work tree (the further
63       the directory that contains .gitattributes is from the path in
64       question, the lower its precedence). Finally global and system-wide
65       files are considered (they have the lowest precedence).
66
67       When the .gitattributes file is missing from the work tree, the path in
68       the index is used as a fall-back. During checkout process,
69       .gitattributes in the index is used and then the file in the working
70       tree is used as a fall-back.
71
72       If you wish to affect only a single repository (i.e., to assign
73       attributes to files that are particular to one user’s workflow for that
74       repository), then attributes should be placed in the
75       $GIT_DIR/info/attributes file. Attributes which should be
76       version-controlled and distributed to other repositories (i.e.,
77       attributes of interest to all users) should go into .gitattributes
78       files. Attributes that should affect all repositories for a single user
79       should be placed in a file specified by the core.attributesFile
80       configuration option (see git-config(1)). Its default value is
81       $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not set
82       or empty, $HOME/.config/git/attributes is used instead. Attributes for
83       all users on a system should be placed in the
84       $(prefix)/etc/gitattributes file.
85
86       Sometimes you would need to override a setting of an attribute for a
87       path to Unspecified state. This can be done by listing the name of the
88       attribute prefixed with an exclamation point !.
89

EFFECTS

91       Certain operations by Git can be influenced by assigning particular
92       attributes to a path. Currently, the following operations are
93       attributes-aware.
94
95   Checking-out and checking-in
96       These attributes affect how the contents stored in the repository are
97       copied to the working tree files when commands such as git checkout and
98       git merge run. They also affect how Git stores the contents you prepare
99       in the working tree in the repository upon git add and git commit.
100
101       text
102           This attribute enables and controls end-of-line normalization. When
103           a text file is normalized, its line endings are converted to LF in
104           the repository. To control what line ending style is used in the
105           working directory, use the eol attribute for a single file and the
106           core.eol configuration variable for all text files. Note that
107           core.autocrlf overrides core.eol
108
109           Set
110               Setting the text attribute on a path enables end-of-line
111               normalization and marks the path as a text file. End-of-line
112               conversion takes place without guessing the content type.
113
114           Unset
115               Unsetting the text attribute on a path tells Git not to attempt
116               any end-of-line conversion upon checkin or checkout.
117
118           Set to string value "auto"
119               When text is set to "auto", the path is marked for automatic
120               end-of-line conversion. If Git decides that the content is
121               text, its line endings are converted to LF on checkin. When the
122               file has been committed with CRLF, no conversion is done.
123
124           Unspecified
125               If the text attribute is unspecified, Git uses the
126               core.autocrlf configuration variable to determine if the file
127               should be converted.
128
129           Any other value causes Git to act as if text has been left
130           unspecified.
131
132       eol
133           This attribute sets a specific line-ending style to be used in the
134           working directory. It enables end-of-line conversion without any
135           content checks, effectively setting the text attribute. Note that
136           setting this attribute on paths which are in the index with CRLF
137           line endings may make the paths to be considered dirty. Adding the
138           path to the index again will normalize the line endings in the
139           index.
140
141           Set to string value "crlf"
142               This setting forces Git to normalize line endings for this file
143               on checkin and convert them to CRLF when the file is checked
144               out.
145
146           Set to string value "lf"
147               This setting forces Git to normalize line endings to LF on
148               checkin and prevents conversion to CRLF when the file is
149               checked out.
150
151       Backwards compatibility with crlf attribute
152           For backwards compatibility, the crlf attribute is interpreted as
153           follows:
154
155               crlf            text
156               -crlf           -text
157               crlf=input      eol=lf
158
159
160       End-of-line conversion
161           While Git normally leaves file contents alone, it can be configured
162           to normalize line endings to LF in the repository and, optionally,
163           to convert them to CRLF when files are checked out.
164
165           If you simply want to have CRLF line endings in your working
166           directory regardless of the repository you are working with, you
167           can set the config variable "core.autocrlf" without using any
168           attributes.
169
170               [core]
171                       autocrlf = true
172
173
174           This does not force normalization of text files, but does ensure
175           that text files that you introduce to the repository have their
176           line endings normalized to LF when they are added, and that files
177           that are already normalized in the repository stay normalized.
178
179           If you want to ensure that text files that any contributor
180           introduces to the repository have their line endings normalized,
181           you can set the text attribute to "auto" for all files.
182
183               *       text=auto
184
185
186           The attributes allow a fine-grained control, how the line endings
187           are converted. Here is an example that will make Git normalize
188           .txt, .vcproj and .sh files, ensure that .vcproj files have CRLF
189           and .sh files have LF in the working directory, and prevent .jpg
190           files from being normalized regardless of their content.
191
192               *               text=auto
193               *.txt           text
194               *.vcproj        text eol=crlf
195               *.sh            text eol=lf
196               *.jpg           -text
197
198
199               Note
200               When text=auto conversion is enabled in a cross-platform
201               project using push and pull to a central repository the text
202               files containing CRLFs should be normalized.
203
204           From a clean working directory:
205
206               $ echo "* text=auto" >.gitattributes
207               $ git add --renormalize .
208               $ git status        # Show files that will be normalized
209               $ git commit -m "Introduce end-of-line normalization"
210
211
212           If any files that should not be normalized show up in git status,
213           unset their text attribute before running git add -u.
214
215               manual.pdf      -text
216
217
218           Conversely, text files that Git does not detect can have
219           normalization enabled manually.
220
221               weirdchars.txt  text
222
223
224           If core.safecrlf is set to "true" or "warn", Git verifies if the
225           conversion is reversible for the current setting of core.autocrlf.
226           For "true", Git rejects irreversible conversions; for "warn", Git
227           only prints a warning but accepts an irreversible conversion. The
228           safety triggers to prevent such a conversion done to the files in
229           the work tree, but there are a few exceptions. Even though...
230
231           ·   git add itself does not touch the files in the work tree, the
232               next checkout would, so the safety triggers;
233
234           ·   git apply to update a text file with a patch does touch the
235               files in the work tree, but the operation is about text files
236               and CRLF conversion is about fixing the line ending
237               inconsistencies, so the safety does not trigger;
238
239           ·   git diff itself does not touch the files in the work tree, it
240               is often run to inspect the changes you intend to next git add.
241               To catch potential problems early, safety triggers.
242
243       working-tree-encoding
244           Git recognizes files encoded in ASCII or one of its supersets (e.g.
245           UTF-8, ISO-8859-1, ...) as text files. Files encoded in certain
246           other encodings (e.g. UTF-16) are interpreted as binary and
247           consequently built-in Git text processing tools (e.g. git diff) as
248           well as most Git web front ends do not visualize the contents of
249           these files by default.
250
251           In these cases you can tell Git the encoding of a file in the
252           working directory with the working-tree-encoding attribute. If a
253           file with this attribute is added to Git, then Git reencodes the
254           content from the specified encoding to UTF-8. Finally, Git stores
255           the UTF-8 encoded content in its internal data structure (called
256           "the index"). On checkout the content is reencoded back to the
257           specified encoding.
258
259           Please note that using the working-tree-encoding attribute may have
260           a number of pitfalls:
261
262           ·   Alternative Git implementations (e.g. JGit or libgit2) and
263               older Git versions (as of March 2018) do not support the
264               working-tree-encoding attribute. If you decide to use the
265               working-tree-encoding attribute in your repository, then it is
266               strongly recommended to ensure that all clients working with
267               the repository support it.
268
269               For example, Microsoft Visual Studio resources files (*.rc) or
270               PowerShell script files (*.ps1) are sometimes encoded in
271               UTF-16. If you declare *.ps1 as files as UTF-16 and you add
272               foo.ps1 with a working-tree-encoding enabled Git client, then
273               foo.ps1 will be stored as UTF-8 internally. A client without
274               working-tree-encoding support will checkout foo.ps1 as UTF-8
275               encoded file. This will typically cause trouble for the users
276               of this file.
277
278               If a Git client, that does not support the
279               working-tree-encoding attribute, adds a new file bar.ps1, then
280               bar.ps1 will be stored "as-is" internally (in this example
281               probably as UTF-16). A client with working-tree-encoding
282               support will interpret the internal contents as UTF-8 and try
283               to convert it to UTF-16 on checkout. That operation will fail
284               and cause an error.
285
286           ·   Reencoding content to non-UTF encodings can cause errors as the
287               conversion might not be UTF-8 round trip safe. If you suspect
288               your encoding to not be round trip safe, then add it to
289               core.checkRoundtripEncoding to make Git check the round trip
290               encoding (see git-config(1)). SHIFT-JIS (Japanese character
291               set) is known to have round trip issues with UTF-8 and is
292               checked by default.
293
294           ·   Reencoding content requires resources that might slow down
295               certain Git operations (e.g git checkout or git add).
296
297           Use the working-tree-encoding attribute only if you cannot store a
298           file in UTF-8 encoding and if you want Git to be able to process
299           the content as text.
300
301           As an example, use the following attributes if your *.ps1 files are
302           UTF-16 encoded with byte order mark (BOM) and you want Git to
303           perform automatic line ending conversion based on your platform.
304
305               *.ps1           text working-tree-encoding=UTF-16
306
307
308           Use the following attributes if your *.ps1 files are UTF-16 little
309           endian encoded without BOM and you want Git to use Windows line
310           endings in the working directory. Please note, it is highly
311           recommended to explicitly define the line endings with eol if the
312           working-tree-encoding attribute is used to avoid ambiguity.
313
314               *.ps1           text working-tree-encoding=UTF-16LE eol=CRLF
315
316
317           You can get a list of all available encodings on your platform with
318           the following command:
319
320               iconv --list
321
322
323           If you do not know the encoding of a file, then you can use the
324           file command to guess the encoding:
325
326               file foo.ps1
327
328
329       ident
330           When the attribute ident is set for a path, Git replaces $Id$ in
331           the blob object with $Id:, followed by the 40-character hexadecimal
332           blob object name, followed by a dollar sign $ upon checkout. Any
333           byte sequence that begins with $Id: and ends with $ in the worktree
334           file is replaced with $Id$ upon check-in.
335
336       filter
337           A filter attribute can be set to a string value that names a filter
338           driver specified in the configuration.
339
340           A filter driver consists of a clean command and a smudge command,
341           either of which can be left unspecified. Upon checkout, when the
342           smudge command is specified, the command is fed the blob object
343           from its standard input, and its standard output is used to update
344           the worktree file. Similarly, the clean command is used to convert
345           the contents of worktree file upon checkin. By default these
346           commands process only a single blob and terminate. If a long
347           running process filter is used in place of clean and/or smudge
348           filters, then Git can process all blobs with a single filter
349           command invocation for the entire life of a single Git command, for
350           example git add --all. If a long running process filter is
351           configured then it always takes precedence over a configured single
352           blob filter. See section below for the description of the protocol
353           used to communicate with a process filter.
354
355           One use of the content filtering is to massage the content into a
356           shape that is more convenient for the platform, filesystem, and the
357           user to use. For this mode of operation, the key phrase here is
358           "more convenient" and not "turning something unusable into usable".
359           In other words, the intent is that if someone unsets the filter
360           driver definition, or does not have the appropriate filter program,
361           the project should still be usable.
362
363           Another use of the content filtering is to store the content that
364           cannot be directly used in the repository (e.g. a UUID that refers
365           to the true content stored outside Git, or an encrypted content)
366           and turn it into a usable form upon checkout (e.g. download the
367           external content, or decrypt the encrypted content).
368
369           These two filters behave differently, and by default, a filter is
370           taken as the former, massaging the contents into more convenient
371           shape. A missing filter driver definition in the config, or a
372           filter driver that exits with a non-zero status, is not an error
373           but makes the filter a no-op passthru.
374
375           You can declare that a filter turns a content that by itself is
376           unusable into a usable content by setting the
377           filter.<driver>.required configuration variable to true.
378
379           Note: Whenever the clean filter is changed, the repo should be
380           renormalized: $ git add --renormalize .
381
382           For example, in .gitattributes, you would assign the filter
383           attribute for paths.
384
385               *.c     filter=indent
386
387
388           Then you would define a "filter.indent.clean" and
389           "filter.indent.smudge" configuration in your .git/config to specify
390           a pair of commands to modify the contents of C programs when the
391           source files are checked in ("clean" is run) and checked out (no
392           change is made because the command is "cat").
393
394               [filter "indent"]
395                       clean = indent
396                       smudge = cat
397
398
399           For best results, clean should not alter its output further if it
400           is run twice ("clean→clean" should be equivalent to "clean"), and
401           multiple smudge commands should not alter clean's output
402           ("smudge→smudge→clean" should be equivalent to "clean"). See the
403           section on merging below.
404
405           The "indent" filter is well-behaved in this regard: it will not
406           modify input that is already correctly indented. In this case, the
407           lack of a smudge filter means that the clean filter must accept its
408           own output without modifying it.
409
410           If a filter must succeed in order to make the stored contents
411           usable, you can declare that the filter is required, in the
412           configuration:
413
414               [filter "crypt"]
415                       clean = openssl enc ...
416                       smudge = openssl enc -d ...
417                       required
418
419
420           Sequence "%f" on the filter command line is replaced with the name
421           of the file the filter is working on. A filter might use this in
422           keyword substitution. For example:
423
424               [filter "p4"]
425                       clean = git-p4-filter --clean %f
426                       smudge = git-p4-filter --smudge %f
427
428
429           Note that "%f" is the name of the path that is being worked on.
430           Depending on the version that is being filtered, the corresponding
431           file on disk may not exist, or may have different contents. So,
432           smudge and clean commands should not try to access the file on
433           disk, but only act as filters on the content provided to them on
434           standard input.
435
436       Long Running Filter Process
437           If the filter command (a string value) is defined via
438           filter.<driver>.process then Git can process all blobs with a
439           single filter invocation for the entire life of a single Git
440           command. This is achieved by using the long-running process
441           protocol (described in
442           technical/long-running-process-protocol.txt).
443
444           When Git encounters the first file that needs to be cleaned or
445           smudged, it starts the filter and performs the handshake. In the
446           handshake, the welcome message sent by Git is "git-filter-client",
447           only version 2 is suppported, and the supported capabilities are
448           "clean", "smudge", and "delay".
449
450           Afterwards Git sends a list of "key=value" pairs terminated with a
451           flush packet. The list will contain at least the filter command
452           (based on the supported capabilities) and the pathname of the file
453           to filter relative to the repository root. Right after the flush
454           packet Git sends the content split in zero or more pkt-line packets
455           and a flush packet to terminate content. Please note, that the
456           filter must not send any response before it received the content
457           and the final flush packet. Also note that the "value" of a
458           "key=value" pair can contain the "=" character whereas the key
459           would never contain that character.
460
461               packet:          git> command=smudge
462               packet:          git> pathname=path/testfile.dat
463               packet:          git> 0000
464               packet:          git> CONTENT
465               packet:          git> 0000
466
467
468           The filter is expected to respond with a list of "key=value" pairs
469           terminated with a flush packet. If the filter does not experience
470           problems then the list must contain a "success" status. Right after
471           these packets the filter is expected to send the content in zero or
472           more pkt-line packets and a flush packet at the end. Finally, a
473           second list of "key=value" pairs terminated with a flush packet is
474           expected. The filter can change the status in the second list or
475           keep the status as is with an empty list. Please note that the
476           empty list must be terminated with a flush packet regardless.
477
478               packet:          git< status=success
479               packet:          git< 0000
480               packet:          git< SMUDGED_CONTENT
481               packet:          git< 0000
482               packet:          git< 0000  # empty list, keep "status=success" unchanged!
483
484
485           If the result content is empty then the filter is expected to
486           respond with a "success" status and a flush packet to signal the
487           empty content.
488
489               packet:          git< status=success
490               packet:          git< 0000
491               packet:          git< 0000  # empty content!
492               packet:          git< 0000  # empty list, keep "status=success" unchanged!
493
494
495           In case the filter cannot or does not want to process the content,
496           it is expected to respond with an "error" status.
497
498               packet:          git< status=error
499               packet:          git< 0000
500
501
502           If the filter experiences an error during processing, then it can
503           send the status "error" after the content was (partially or
504           completely) sent.
505
506               packet:          git< status=success
507               packet:          git< 0000
508               packet:          git< HALF_WRITTEN_ERRONEOUS_CONTENT
509               packet:          git< 0000
510               packet:          git< status=error
511               packet:          git< 0000
512
513
514           In case the filter cannot or does not want to process the content
515           as well as any future content for the lifetime of the Git process,
516           then it is expected to respond with an "abort" status at any point
517           in the protocol.
518
519               packet:          git< status=abort
520               packet:          git< 0000
521
522
523           Git neither stops nor restarts the filter process in case the
524           "error"/"abort" status is set. However, Git sets its exit code
525           according to the filter.<driver>.required flag, mimicking the
526           behavior of the filter.<driver>.clean / filter.<driver>.smudge
527           mechanism.
528
529           If the filter dies during the communication or does not adhere to
530           the protocol then Git will stop the filter process and restart it
531           with the next file that needs to be processed. Depending on the
532           filter.<driver>.required flag Git will interpret that as error.
533
534       Delay
535           If the filter supports the "delay" capability, then Git can send
536           the flag "can-delay" after the filter command and pathname. This
537           flag denotes that the filter can delay filtering the current blob
538           (e.g. to compensate network latencies) by responding with no
539           content but with the status "delayed" and a flush packet.
540
541               packet:          git> command=smudge
542               packet:          git> pathname=path/testfile.dat
543               packet:          git> can-delay=1
544               packet:          git> 0000
545               packet:          git> CONTENT
546               packet:          git> 0000
547               packet:          git< status=delayed
548               packet:          git< 0000
549
550
551           If the filter supports the "delay" capability then it must support
552           the "list_available_blobs" command. If Git sends this command, then
553           the filter is expected to return a list of pathnames representing
554           blobs that have been delayed earlier and are now available. The
555           list must be terminated with a flush packet followed by a "success"
556           status that is also terminated with a flush packet. If no blobs for
557           the delayed paths are available, yet, then the filter is expected
558           to block the response until at least one blob becomes available.
559           The filter can tell Git that it has no more delayed blobs by
560           sending an empty list. As soon as the filter responds with an empty
561           list, Git stops asking. All blobs that Git has not received at this
562           point are considered missing and will result in an error.
563
564               packet:          git> command=list_available_blobs
565               packet:          git> 0000
566               packet:          git< pathname=path/testfile.dat
567               packet:          git< pathname=path/otherfile.dat
568               packet:          git< 0000
569               packet:          git< status=success
570               packet:          git< 0000
571
572
573           After Git received the pathnames, it will request the corresponding
574           blobs again. These requests contain a pathname and an empty content
575           section. The filter is expected to respond with the smudged content
576           in the usual way as explained above.
577
578               packet:          git> command=smudge
579               packet:          git> pathname=path/testfile.dat
580               packet:          git> 0000
581               packet:          git> 0000  # empty content!
582               packet:          git< status=success
583               packet:          git< 0000
584               packet:          git< SMUDGED_CONTENT
585               packet:          git< 0000
586               packet:          git< 0000  # empty list, keep "status=success" unchanged!
587
588
589       Example
590           A long running filter demo implementation can be found in
591           contrib/long-running-filter/example.pl located in the Git core
592           repository. If you develop your own long running filter process
593           then the GIT_TRACE_PACKET environment variables can be very helpful
594           for debugging (see git(1)).
595
596           Please note that you cannot use an existing filter.<driver>.clean
597           or filter.<driver>.smudge command with filter.<driver>.process
598           because the former two use a different inter process communication
599           protocol than the latter one.
600
601       Interaction between checkin/checkout attributes
602           In the check-in codepath, the worktree file is first converted with
603           filter driver (if specified and corresponding driver defined), then
604           the result is processed with ident (if specified), and then finally
605           with text (again, if specified and applicable).
606
607           In the check-out codepath, the blob content is first converted with
608           text, and then ident and fed to filter.
609
610       Merging branches with differing checkin/checkout attributes
611           If you have added attributes to a file that cause the canonical
612           repository format for that file to change, such as adding a
613           clean/smudge filter or text/eol/ident attributes, merging anything
614           where the attribute is not in place would normally cause merge
615           conflicts.
616
617           To prevent these unnecessary merge conflicts, Git can be told to
618           run a virtual check-out and check-in of all three stages of a file
619           when resolving a three-way merge by setting the merge.renormalize
620           configuration variable. This prevents changes caused by check-in
621           conversion from causing spurious merge conflicts when a converted
622           file is merged with an unconverted file.
623
624           As long as a "smudge→clean" results in the same output as a "clean"
625           even on files that are already smudged, this strategy will
626           automatically resolve all filter-related conflicts. Filters that do
627           not act in this way may cause additional merge conflicts that must
628           be resolved manually.
629
630   Generating diff text
631       diff
632           The attribute diff affects how Git generates diffs for particular
633           files. It can tell Git whether to generate a textual patch for the
634           path or to treat the path as a binary file. It can also affect what
635           line is shown on the hunk header @@ -k,l +n,m @@ line, tell Git to
636           use an external command to generate the diff, or ask Git to convert
637           binary files to a text format before generating the diff.
638
639           Set
640               A path to which the diff attribute is set is treated as text,
641               even when they contain byte values that normally never appear
642               in text files, such as NUL.
643
644           Unset
645               A path to which the diff attribute is unset will generate
646               Binary files differ (or a binary patch, if binary patches are
647               enabled).
648
649           Unspecified
650               A path to which the diff attribute is unspecified first gets
651               its contents inspected, and if it looks like text and is
652               smaller than core.bigFileThreshold, it is treated as text.
653               Otherwise it would generate Binary files differ.
654
655           String
656               Diff is shown using the specified diff driver. Each driver may
657               specify one or more options, as described in the following
658               section. The options for the diff driver "foo" are defined by
659               the configuration variables in the "diff.foo" section of the
660               Git config file.
661
662       Defining an external diff driver
663           The definition of a diff driver is done in gitconfig, not
664           gitattributes file, so strictly speaking this manual page is a
665           wrong place to talk about it. However...
666
667           To define an external diff driver jcdiff, add a section to your
668           $GIT_DIR/config file (or $HOME/.gitconfig file) like this:
669
670               [diff "jcdiff"]
671                       command = j-c-diff
672
673
674           When Git needs to show you a diff for the path with diff attribute
675           set to jcdiff, it calls the command you specified with the above
676           configuration, i.e. j-c-diff, with 7 parameters, just like
677           GIT_EXTERNAL_DIFF program is called. See git(1) for details.
678
679       Defining a custom hunk-header
680           Each group of changes (called a "hunk") in the textual diff output
681           is prefixed with a line of the form:
682
683               @@ -k,l +n,m @@ TEXT
684
685           This is called a hunk header. The "TEXT" portion is by default a
686           line that begins with an alphabet, an underscore or a dollar sign;
687           this matches what GNU diff -p output uses. This default selection
688           however is not suited for some contents, and you can use a
689           customized pattern to make a selection.
690
691           First, in .gitattributes, you would assign the diff attribute for
692           paths.
693
694               *.tex   diff=tex
695
696
697           Then, you would define a "diff.tex.xfuncname" configuration to
698           specify a regular expression that matches a line that you would
699           want to appear as the hunk header "TEXT". Add a section to your
700           $GIT_DIR/config file (or $HOME/.gitconfig file) like this:
701
702               [diff "tex"]
703                       xfuncname = "^(\\\\(sub)*section\\{.*)$"
704
705
706           Note. A single level of backslashes are eaten by the configuration
707           file parser, so you would need to double the backslashes; the
708           pattern above picks a line that begins with a backslash, and zero
709           or more occurrences of sub followed by section followed by open
710           brace, to the end of line.
711
712           There are a few built-in patterns to make this easier, and tex is
713           one of them, so you do not have to write the above in your
714           configuration file (you still need to enable this with the
715           attribute mechanism, via .gitattributes). The following built in
716           patterns are available:
717
718           ·   ada suitable for source code in the Ada language.
719
720           ·   bibtex suitable for files with BibTeX coded references.
721
722           ·   cpp suitable for source code in the C and C++ languages.
723
724           ·   csharp suitable for source code in the C# language.
725
726           ·   css suitable for cascading style sheets.
727
728           ·   fortran suitable for source code in the Fortran language.
729
730           ·   fountain suitable for Fountain documents.
731
732           ·   golang suitable for source code in the Go language.
733
734           ·   html suitable for HTML/XHTML documents.
735
736           ·   java suitable for source code in the Java language.
737
738           ·   matlab suitable for source code in the MATLAB language.
739
740           ·   objc suitable for source code in the Objective-C language.
741
742           ·   pascal suitable for source code in the Pascal/Delphi language.
743
744           ·   perl suitable for source code in the Perl language.
745
746           ·   php suitable for source code in the PHP language.
747
748           ·   python suitable for source code in the Python language.
749
750           ·   ruby suitable for source code in the Ruby language.
751
752           ·   tex suitable for source code for LaTeX documents.
753
754       Customizing word diff
755           You can customize the rules that git diff --word-diff uses to split
756           words in a line, by specifying an appropriate regular expression in
757           the "diff.*.wordRegex" configuration variable. For example, in TeX
758           a backslash followed by a sequence of letters forms a command, but
759           several such commands can be run together without intervening
760           whitespace. To separate them, use a regular expression in your
761           $GIT_DIR/config file (or $HOME/.gitconfig file) like this:
762
763               [diff "tex"]
764                       wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"
765
766
767           A built-in pattern is provided for all languages listed in the
768           previous section.
769
770       Performing text diffs of binary files
771           Sometimes it is desirable to see the diff of a text-converted
772           version of some binary files. For example, a word processor
773           document can be converted to an ASCII text representation, and the
774           diff of the text shown. Even though this conversion loses some
775           information, the resulting diff is useful for human viewing (but
776           cannot be applied directly).
777
778           The textconv config option is used to define a program for
779           performing such a conversion. The program should take a single
780           argument, the name of a file to convert, and produce the resulting
781           text on stdout.
782
783           For example, to show the diff of the exif information of a file
784           instead of the binary information (assuming you have the exif tool
785           installed), add the following section to your $GIT_DIR/config file
786           (or $HOME/.gitconfig file):
787
788               [diff "jpg"]
789                       textconv = exif
790
791
792               Note
793               The text conversion is generally a one-way conversion; in this
794               example, we lose the actual image contents and focus just on
795               the text data. This means that diffs generated by textconv are
796               not suitable for applying. For this reason, only git diff and
797               the git log family of commands (i.e., log, whatchanged, show)
798               will perform text conversion. git format-patch will never
799               generate this output. If you want to send somebody a
800               text-converted diff of a binary file (e.g., because it quickly
801               conveys the changes you have made), you should generate it
802               separately and send it as a comment in addition to the usual
803               binary diff that you might send.
804
805           Because text conversion can be slow, especially when doing a large
806           number of them with git log -p, Git provides a mechanism to cache
807           the output and use it in future diffs. To enable caching, set the
808           "cachetextconv" variable in your diff driver’s config. For example:
809
810               [diff "jpg"]
811                       textconv = exif
812                       cachetextconv = true
813
814
815           This will cache the result of running "exif" on each blob
816           indefinitely. If you change the textconv config variable for a diff
817           driver, Git will automatically invalidate the cache entries and
818           re-run the textconv filter. If you want to invalidate the cache
819           manually (e.g., because your version of "exif" was updated and now
820           produces better output), you can remove the cache manually with git
821           update-ref -d refs/notes/textconv/jpg (where "jpg" is the name of
822           the diff driver, as in the example above).
823
824       Choosing textconv versus external diff
825           If you want to show differences between binary or
826           specially-formatted blobs in your repository, you can choose to use
827           either an external diff command, or to use textconv to convert them
828           to a diff-able text format. Which method you choose depends on your
829           exact situation.
830
831           The advantage of using an external diff command is flexibility. You
832           are not bound to find line-oriented changes, nor is it necessary
833           for the output to resemble unified diff. You are free to locate and
834           report changes in the most appropriate way for your data format.
835
836           A textconv, by comparison, is much more limiting. You provide a
837           transformation of the data into a line-oriented text format, and
838           Git uses its regular diff tools to generate the output. There are
839           several advantages to choosing this method:
840
841            1. Ease of use. It is often much simpler to write a binary to text
842               transformation than it is to perform your own diff. In many
843               cases, existing programs can be used as textconv filters (e.g.,
844               exif, odt2txt).
845
846            2. Git diff features. By performing only the transformation step
847               yourself, you can still utilize many of Git’s diff features,
848               including colorization, word-diff, and combined diffs for
849               merges.
850
851            3. Caching. Textconv caching can speed up repeated diffs, such as
852               those you might trigger by running git log -p.
853
854       Marking files as binary
855           Git usually guesses correctly whether a blob contains text or
856           binary data by examining the beginning of the contents. However,
857           sometimes you may want to override its decision, either because a
858           blob contains binary data later in the file, or because the
859           content, while technically composed of text characters, is opaque
860           to a human reader. For example, many postscript files contain only
861           ASCII characters, but produce noisy and meaningless diffs.
862
863           The simplest way to mark a file as binary is to unset the diff
864           attribute in the .gitattributes file:
865
866               *.ps -diff
867
868
869           This will cause Git to generate Binary files differ (or a binary
870           patch, if binary patches are enabled) instead of a regular diff.
871
872           However, one may also want to specify other diff driver attributes.
873           For example, you might want to use textconv to convert postscript
874           files to an ASCII representation for human viewing, but otherwise
875           treat them as binary files. You cannot specify both -diff and
876           diff=ps attributes. The solution is to use the diff.*.binary config
877           option:
878
879               [diff "ps"]
880                 textconv = ps2ascii
881                 binary = true
882
883
884   Performing a three-way merge
885       merge
886           The attribute merge affects how three versions of a file are merged
887           when a file-level merge is necessary during git merge, and other
888           commands such as git revert and git cherry-pick.
889
890           Set
891               Built-in 3-way merge driver is used to merge the contents in a
892               way similar to merge command of RCS suite. This is suitable for
893               ordinary text files.
894
895           Unset
896               Take the version from the current branch as the tentative merge
897               result, and declare that the merge has conflicts. This is
898               suitable for binary files that do not have a well-defined merge
899               semantics.
900
901           Unspecified
902               By default, this uses the same built-in 3-way merge driver as
903               is the case when the merge attribute is set. However, the
904               merge.default configuration variable can name different merge
905               driver to be used with paths for which the merge attribute is
906               unspecified.
907
908           String
909               3-way merge is performed using the specified custom merge
910               driver. The built-in 3-way merge driver can be explicitly
911               specified by asking for "text" driver; the built-in "take the
912               current branch" driver can be requested with "binary".
913
914       Built-in merge drivers
915           There are a few built-in low-level merge drivers defined that can
916           be asked for via the merge attribute.
917
918           text
919               Usual 3-way file level merge for text files. Conflicted regions
920               are marked with conflict markers <<<<<<<, ======= and >>>>>>>.
921               The version from your branch appears before the ======= marker,
922               and the version from the merged branch appears after the
923               ======= marker.
924
925           binary
926               Keep the version from your branch in the work tree, but leave
927               the path in the conflicted state for the user to sort out.
928
929           union
930               Run 3-way file level merge for text files, but take lines from
931               both versions, instead of leaving conflict markers. This tends
932               to leave the added lines in the resulting file in random order
933               and the user should verify the result. Do not use this if you
934               do not understand the implications.
935
936       Defining a custom merge driver
937           The definition of a merge driver is done in the .git/config file,
938           not in the gitattributes file, so strictly speaking this manual
939           page is a wrong place to talk about it. However...
940
941           To define a custom merge driver filfre, add a section to your
942           $GIT_DIR/config file (or $HOME/.gitconfig file) like this:
943
944               [merge "filfre"]
945                       name = feel-free merge driver
946                       driver = filfre %O %A %B %L %P
947                       recursive = binary
948
949
950           The merge.*.name variable gives the driver a human-readable name.
951
952           The ‘merge.*.driver` variable’s value is used to construct a
953           command to run to merge ancestor’s version (%O), current version
954           (%A) and the other branches’ version (%B). These three tokens are
955           replaced with the names of temporary files that hold the contents
956           of these versions when the command line is built. Additionally, %L
957           will be replaced with the conflict marker size (see below).
958
959           The merge driver is expected to leave the result of the merge in
960           the file named with %A by overwriting it, and exit with zero status
961           if it managed to merge them cleanly, or non-zero if there were
962           conflicts.
963
964           The merge.*.recursive variable specifies what other merge driver to
965           use when the merge driver is called for an internal merge between
966           common ancestors, when there are more than one. When left
967           unspecified, the driver itself is used for both internal merge and
968           the final merge.
969
970           The merge driver can learn the pathname in which the merged result
971           will be stored via placeholder %P.
972
973       conflict-marker-size
974           This attribute controls the length of conflict markers left in the
975           work tree file during a conflicted merge. Only setting to the value
976           to a positive integer has any meaningful effect.
977
978           For example, this line in .gitattributes can be used to tell the
979           merge machinery to leave much longer (instead of the usual
980           7-character-long) conflict markers when merging the file
981           Documentation/git-merge.txt results in a conflict.
982
983               Documentation/git-merge.txt     conflict-marker-size=32
984
985
986   Checking whitespace errors
987       whitespace
988           The core.whitespace configuration variable allows you to define
989           what diff and apply should consider whitespace errors for all paths
990           in the project (See git-config(1)). This attribute gives you finer
991           control per path.
992
993           Set
994               Notice all types of potential whitespace errors known to Git.
995               The tab width is taken from the value of the core.whitespace
996               configuration variable.
997
998           Unset
999               Do not notice anything as error.
1000
1001           Unspecified
1002               Use the value of the core.whitespace configuration variable to
1003               decide what to notice as error.
1004
1005           String
1006               Specify a comma separate list of common whitespace problems to
1007               notice in the same format as the core.whitespace configuration
1008               variable.
1009
1010   Creating an archive
1011       export-ignore
1012           Files and directories with the attribute export-ignore won’t be
1013           added to archive files.
1014
1015       export-subst
1016           If the attribute export-subst is set for a file then Git will
1017           expand several placeholders when adding this file to an archive.
1018           The expansion depends on the availability of a commit ID, i.e., if
1019           git-archive(1) has been given a tree instead of a commit or a tag
1020           then no replacement will be done. The placeholders are the same as
1021           those for the option --pretty=format: of git-log(1), except that
1022           they need to be wrapped like this: $Format:PLACEHOLDERS$ in the
1023           file. E.g. the string $Format:%H$ will be replaced by the commit
1024           hash.
1025
1026   Packing objects
1027       delta
1028           Delta compression will not be attempted for blobs for paths with
1029           the attribute delta set to false.
1030
1031   Viewing files in GUI tools
1032       encoding
1033           The value of this attribute specifies the character encoding that
1034           should be used by GUI tools (e.g. gitk(1) and git-gui(1)) to
1035           display the contents of the relevant file. Note that due to
1036           performance considerations gitk(1) does not use this attribute
1037           unless you manually enable per-file encodings in its options.
1038
1039           If this attribute is not set or has an invalid value, the value of
1040           the gui.encoding configuration variable is used instead (See git-
1041           config(1)).
1042

USING MACRO ATTRIBUTES

1044       You do not want any end-of-line conversions applied to, nor textual
1045       diffs produced for, any binary file you track. You would need to
1046       specify e.g.
1047
1048           *.jpg -text -diff
1049
1050
1051       but that may become cumbersome, when you have many attributes. Using
1052       macro attributes, you can define an attribute that, when set, also sets
1053       or unsets a number of other attributes at the same time. The system
1054       knows a built-in macro attribute, binary:
1055
1056           *.jpg binary
1057
1058
1059       Setting the "binary" attribute also unsets the "text" and "diff"
1060       attributes as above. Note that macro attributes can only be "Set",
1061       though setting one might have the effect of setting or unsetting other
1062       attributes or even returning other attributes to the "Unspecified"
1063       state.
1064

DEFINING MACRO ATTRIBUTES

1066       Custom macro attributes can be defined only in top-level gitattributes
1067       files ($GIT_DIR/info/attributes, the .gitattributes file at the top
1068       level of the working tree, or the global or system-wide gitattributes
1069       files), not in .gitattributes files in working tree subdirectories. The
1070       built-in macro attribute "binary" is equivalent to:
1071
1072           [attr]binary -diff -merge -text
1073
1074

EXAMPLES

1076       If you have these three gitattributes file:
1077
1078           (in $GIT_DIR/info/attributes)
1079
1080           a*      foo !bar -baz
1081
1082           (in .gitattributes)
1083           abc     foo bar baz
1084
1085           (in t/.gitattributes)
1086           ab*     merge=filfre
1087           abc     -foo -bar
1088           *.c     frotz
1089
1090
1091       the attributes given to path t/abc are computed as follows:
1092
1093        1. By examining t/.gitattributes (which is in the same directory as
1094           the path in question), Git finds that the first line matches.
1095           merge attribute is set. It also finds that the second line matches,
1096           and attributes foo and bar are unset.
1097
1098        2. Then it examines .gitattributes (which is in the parent directory),
1099           and finds that the first line matches, but t/.gitattributes file
1100           already decided how merge, foo and bar attributes should be given
1101           to this path, so it leaves foo and bar unset. Attribute baz is set.
1102
1103        3. Finally it examines $GIT_DIR/info/attributes. This file is used to
1104           override the in-tree settings. The first line is a match, and foo
1105           is set, bar is reverted to unspecified state, and baz is unset.
1106
1107       As the result, the attributes assignment to t/abc becomes:
1108
1109           foo     set to true
1110           bar     unspecified
1111           baz     set to false
1112           merge   set to string value "filfre"
1113           frotz   unspecified
1114
1115

SEE ALSO

1117       git-check-attr(1).
1118

GIT

1120       Part of the git(1) suite
1121
1122
1123
1124Git 2.20.1                        12/15/2018                  GITATTRIBUTES(5)
Impressum