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

USING MACRO ATTRIBUTES

1022       You do not want any end-of-line conversions applied to, nor textual
1023       diffs produced for, any binary file you track. You would need to
1024       specify e.g.
1025
1026           *.jpg -text -diff
1027
1028       but that may become cumbersome, when you have many attributes. Using
1029       macro attributes, you can define an attribute that, when set, also sets
1030       or unsets a number of other attributes at the same time. The system
1031       knows a built-in macro attribute, binary:
1032
1033           *.jpg binary
1034
1035       Setting the "binary" attribute also unsets the "text" and "diff"
1036       attributes as above. Note that macro attributes can only be "Set",
1037       though setting one might have the effect of setting or unsetting other
1038       attributes or even returning other attributes to the "Unspecified"
1039       state.
1040

DEFINING MACRO ATTRIBUTES

1042       Custom macro attributes can be defined only in top-level gitattributes
1043       files ($GIT_DIR/info/attributes, the .gitattributes file at the top
1044       level of the working tree, or the global or system-wide gitattributes
1045       files), not in .gitattributes files in working tree subdirectories. The
1046       built-in macro attribute "binary" is equivalent to:
1047
1048           [attr]binary -diff -merge -text
1049

EXAMPLES

1051       If you have these three gitattributes file:
1052
1053           (in $GIT_DIR/info/attributes)
1054
1055           a*      foo !bar -baz
1056
1057           (in .gitattributes)
1058           abc     foo bar baz
1059
1060           (in t/.gitattributes)
1061           ab*     merge=filfre
1062           abc     -foo -bar
1063           *.c     frotz
1064
1065       the attributes given to path t/abc are computed as follows:
1066
1067        1. By examining t/.gitattributes (which is in the same directory as
1068           the path in question), Git finds that the first line matches.
1069           merge attribute is set. It also finds that the second line matches,
1070           and attributes foo and bar are unset.
1071
1072        2. Then it examines .gitattributes (which is in the parent directory),
1073           and finds that the first line matches, but t/.gitattributes file
1074           already decided how merge, foo and bar attributes should be given
1075           to this path, so it leaves foo and bar unset. Attribute baz is set.
1076
1077        3. Finally it examines $GIT_DIR/info/attributes. This file is used to
1078           override the in-tree settings. The first line is a match, and foo
1079           is set, bar is reverted to unspecified state, and baz is unset.
1080
1081       As the result, the attributes assignment to t/abc becomes:
1082
1083           foo     set to true
1084           bar     unspecified
1085           baz     set to false
1086           merge   set to string value "filfre"
1087           frotz   unspecified
1088

SEE ALSO

1090       git-check-attr(1).
1091

GIT

1093       Part of the git(1) suite
1094
1095
1096
1097Git 2.26.2                        2020-04-20                  GITATTRIBUTES(5)
Impressum