{
    "mode": "man",
    "parameter": "gitattributes",
    "section": "5",
    "url": "https://www.chedong.com/phpMan.php/man/gitattributes/5/json",
    "generated": "2026-06-13T18:17:31Z",
    "synopsis": "$GITDIR/info/attributes, .gitattributes",
    "sections": {
        "NAME": {
            "content": "gitattributes - Defining attributes per path\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "$GITDIR/info/attributes, .gitattributes\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "A gitattributes file is a simple text file that gives attributes to pathnames.\n\nEach line in gitattributes file is of form:\n\npattern attr1 attr2 ...\n\nThat is, a pattern followed by an attributes list, separated by whitespaces. Leading and\ntrailing whitespaces are ignored. Lines that begin with # are ignored. Patterns that begin\nwith a double quote are quoted in C style. When the pattern matches the path in question, the\nattributes listed on the line are given to the path.\n\nEach attribute can be in one of these states for a given path:\n\nSet\nThe path has the attribute with special value \"true\"; this is specified by listing only\nthe name of the attribute in the attribute list.\n\nUnset\nThe path has the attribute with special value \"false\"; this is specified by listing the\nname of the attribute prefixed with a dash - in the attribute list.\n\nSet to a value\nThe path has the attribute with specified string value; this is specified by listing the\nname of the attribute followed by an equal sign = and its value in the attribute list.\n\nUnspecified\nNo pattern matches the path, and nothing says if the path has or does not have the\nattribute, the attribute for the path is said to be Unspecified.\n\nWhen more than one pattern matches the path, a later line overrides an earlier line. This\noverriding is done per attribute.\n\nThe rules by which the pattern matches paths are the same as in .gitignore files (see\ngitignore(5)), with a few exceptions:\n\n•   negative patterns are forbidden\n\n•   patterns that match a directory do not recursively match paths inside that directory (so\nusing the trailing-slash path/ syntax is pointless in an attributes file; use path/\ninstead)\n\nWhen deciding what attributes are assigned to a path, Git consults $GITDIR/info/attributes\nfile (which has the highest precedence), .gitattributes file in the same directory as the\npath in question, and its parent directories up to the toplevel of the work tree (the further\nthe directory that contains .gitattributes is from the path in question, the lower its\nprecedence). Finally global and system-wide files are considered (they have the lowest\nprecedence).\n\nWhen the .gitattributes file is missing from the work tree, the path in the index is used as\na fall-back. During checkout process, .gitattributes in the index is used and then the file\nin the working tree is used as a fall-back.\n\nIf you wish to affect only a single repository (i.e., to assign attributes to files that are\nparticular to one user’s workflow for that repository), then attributes should be placed in\nthe $GITDIR/info/attributes file. Attributes which should be version-controlled and\ndistributed to other repositories (i.e., attributes of interest to all users) should go into\n.gitattributes files. Attributes that should affect all repositories for a single user should\nbe placed in a file specified by the core.attributesFile configuration option (see git-\nconfig(1)). Its default value is $XDGCONFIGHOME/git/attributes. If $XDGCONFIGHOME is\neither not set or empty, $HOME/.config/git/attributes is used instead. Attributes for all\nusers on a system should be placed in the $(prefix)/etc/gitattributes file.\n\nSometimes you would need to override a setting of an attribute for a path to Unspecified\nstate. This can be done by listing the name of the attribute prefixed with an exclamation\npoint !.\n",
            "subsections": []
        },
        "EFFECTS": {
            "content": "Certain operations by Git can be influenced by assigning particular attributes to a path.\nCurrently, the following operations are attributes-aware.\n",
            "subsections": [
                {
                    "name": "Checking-out and checking-in",
                    "content": "These attributes affect how the contents stored in the repository are copied to the working\ntree files when commands such as git switch, git checkout and git merge run. They also affect\nhow Git stores the contents you prepare in the working tree in the repository upon git add\nand git commit.\n"
                },
                {
                    "name": "text",
                    "content": "This attribute enables and controls end-of-line normalization. When a text file is\nnormalized, its line endings are converted to LF in the repository. To control what line\nending style is used in the working directory, use the eol attribute for a single file\nand the core.eol configuration variable for all text files. Note that setting\ncore.autocrlf to true or input overrides core.eol (see the definitions of those options\nin git-config(1)).\n\nSet\nSetting the text attribute on a path enables end-of-line normalization and marks the\npath as a text file. End-of-line conversion takes place without guessing the content\ntype.\n\nUnset\nUnsetting the text attribute on a path tells Git not to attempt any end-of-line\nconversion upon checkin or checkout.\n\nSet to string value \"auto\"\nWhen text is set to \"auto\", the path is marked for automatic end-of-line conversion.\nIf Git decides that the content is text, its line endings are converted to LF on\ncheckin. When the file has been committed with CRLF, no conversion is done.\n\nUnspecified\nIf the text attribute is unspecified, Git uses the core.autocrlf configuration\nvariable to determine if the file should be converted.\n\nAny other value causes Git to act as if text has been left unspecified.\n"
                },
                {
                    "name": "eol",
                    "content": "This attribute sets a specific line-ending style to be used in the working directory. It\nenables end-of-line conversion without any content checks, effectively setting the text\nattribute. Note that setting this attribute on paths which are in the index with CRLF\nline endings may make the paths to be considered dirty. Adding the path to the index\nagain will normalize the line endings in the index.\n\nSet to string value \"crlf\"\nThis setting forces Git to normalize line endings for this file on checkin and\nconvert them to CRLF when the file is checked out.\n\nSet to string value \"lf\"\nThis setting forces Git to normalize line endings to LF on checkin and prevents\nconversion to CRLF when the file is checked out.\n"
                },
                {
                    "name": "Backwards compatibility with crlf attribute",
                    "content": "For backwards compatibility, the crlf attribute is interpreted as follows:\n\ncrlf            text\n-crlf           -text\ncrlf=input      eol=lf\n\n"
                },
                {
                    "name": "End-of-line conversion",
                    "content": "While Git normally leaves file contents alone, it can be configured to normalize line\nendings to LF in the repository and, optionally, to convert them to CRLF when files are\nchecked out.\n\nIf you simply want to have CRLF line endings in your working directory regardless of the\nrepository you are working with, you can set the config variable \"core.autocrlf\" without\nusing any attributes.\n\n[core]\nautocrlf = true\n\n\nThis does not force normalization of text files, but does ensure that text files that you\nintroduce to the repository have their line endings normalized to LF when they are added,\nand that files that are already normalized in the repository stay normalized.\n\nIf you want to ensure that text files that any contributor introduces to the repository\nhave their line endings normalized, you can set the text attribute to \"auto\" for all\nfiles.\n\n*       text=auto\n\n\nThe attributes allow a fine-grained control, how the line endings are converted. Here is\nan example that will make Git normalize .txt, .vcproj and .sh files, ensure that .vcproj\nfiles have CRLF and .sh files have LF in the working directory, and prevent .jpg files\nfrom being normalized regardless of their content.\n\n*               text=auto\n*.txt           text\n*.vcproj        text eol=crlf\n*.sh            text eol=lf\n*.jpg           -text\n\n\nNote\nWhen text=auto conversion is enabled in a cross-platform project using push and pull\nto a central repository the text files containing CRLFs should be normalized.\n\nFrom a clean working directory:\n\n$ echo \"* text=auto\" >.gitattributes\n$ git add --renormalize .\n$ git status        # Show files that will be normalized\n$ git commit -m \"Introduce end-of-line normalization\"\n\n\nIf any files that should not be normalized show up in git status, unset their text\nattribute before running git add -u.\n\nmanual.pdf      -text\n\n\nConversely, text files that Git does not detect can have normalization enabled manually.\n\nweirdchars.txt  text\n\n\nIf core.safecrlf is set to \"true\" or \"warn\", Git verifies if the conversion is reversible\nfor the current setting of core.autocrlf. For \"true\", Git rejects irreversible\nconversions; for \"warn\", Git only prints a warning but accepts an irreversible\nconversion. The safety triggers to prevent such a conversion done to the files in the\nwork tree, but there are a few exceptions. Even though...\n\n•   git add itself does not touch the files in the work tree, the next checkout would, so\nthe safety triggers;\n\n•   git apply to update a text file with a patch does touch the files in the work tree,\nbut the operation is about text files and CRLF conversion is about fixing the line\nending inconsistencies, so the safety does not trigger;\n\n•   git diff itself does not touch the files in the work tree, it is often run to inspect\nthe changes you intend to next git add. To catch potential problems early, safety\ntriggers.\n"
                },
                {
                    "name": "working-tree-encoding",
                    "content": "Git recognizes files encoded in ASCII or one of its supersets (e.g. UTF-8, ISO-8859-1,\n...) as text files. Files encoded in certain other encodings (e.g. UTF-16) are\ninterpreted as binary and consequently built-in Git text processing tools (e.g. git diff)\nas well as most Git web front ends do not visualize the contents of these files by\ndefault.\n\nIn these cases you can tell Git the encoding of a file in the working directory with the\nworking-tree-encoding attribute. If a file with this attribute is added to Git, then Git\nre-encodes the content from the specified encoding to UTF-8. Finally, Git stores the\nUTF-8 encoded content in its internal data structure (called \"the index\"). On checkout\nthe content is re-encoded back to the specified encoding.\n\nPlease note that using the working-tree-encoding attribute may have a number of pitfalls:\n\n•   Alternative Git implementations (e.g. JGit or libgit2) and older Git versions (as of\nMarch 2018) do not support the working-tree-encoding attribute. If you decide to use\nthe working-tree-encoding attribute in your repository, then it is strongly\nrecommended to ensure that all clients working with the repository support it.\n\nFor example, Microsoft Visual Studio resources files (*.rc) or PowerShell script\nfiles (*.ps1) are sometimes encoded in UTF-16. If you declare *.ps1 as files as\nUTF-16 and you add foo.ps1 with a working-tree-encoding enabled Git client, then\nfoo.ps1 will be stored as UTF-8 internally. A client without working-tree-encoding\nsupport will checkout foo.ps1 as UTF-8 encoded file. This will typically cause\ntrouble for the users of this file.\n\nIf a Git client that does not support the working-tree-encoding attribute adds a new\nfile bar.ps1, then bar.ps1 will be stored \"as-is\" internally (in this example\nprobably as UTF-16). A client with working-tree-encoding support will interpret the\ninternal contents as UTF-8 and try to convert it to UTF-16 on checkout. That\noperation will fail and cause an error.\n\n•   Reencoding content to non-UTF encodings can cause errors as the conversion might not\nbe UTF-8 round trip safe. If you suspect your encoding to not be round trip safe,\nthen add it to core.checkRoundtripEncoding to make Git check the round trip encoding\n(see git-config(1)). SHIFT-JIS (Japanese character set) is known to have round trip\nissues with UTF-8 and is checked by default.\n\n•   Reencoding content requires resources that might slow down certain Git operations\n(e.g git checkout or git add).\n\nUse the working-tree-encoding attribute only if you cannot store a file in UTF-8 encoding\nand if you want Git to be able to process the content as text.\n\nAs an example, use the following attributes if your *.ps1 files are UTF-16 encoded with\nbyte order mark (BOM) and you want Git to perform automatic line ending conversion based\non your platform.\n\n*.ps1           text working-tree-encoding=UTF-16\n\n\nUse the following attributes if your *.ps1 files are UTF-16 little endian encoded without\nBOM and you want Git to use Windows line endings in the working directory (use\nUTF-16LE-BOM instead of UTF-16LE if you want UTF-16 little endian with BOM). Please note,\nit is highly recommended to explicitly define the line endings with eol if the\nworking-tree-encoding attribute is used to avoid ambiguity.\n\n*.ps1           text working-tree-encoding=UTF-16LE eol=CRLF\n\n\nYou can get a list of all available encodings on your platform with the following\ncommand:\n\niconv --list\n\n\nIf you do not know the encoding of a file, then you can use the file command to guess the\nencoding:\n\nfile foo.ps1\n\n"
                },
                {
                    "name": "ident",
                    "content": "When the attribute ident is set for a path, Git replaces $Id$ in the blob object with\n$Id:, followed by the 40-character hexadecimal blob object name, followed by a dollar\nsign $ upon checkout. Any byte sequence that begins with $Id: and ends with $ in the\nworktree file is replaced with $Id$ upon check-in.\n"
                },
                {
                    "name": "filter",
                    "content": "A filter attribute can be set to a string value that names a filter driver specified in\nthe configuration.\n\nA filter driver consists of a clean command and a smudge command, either of which can be\nleft unspecified. Upon checkout, when the smudge command is specified, the command is fed\nthe blob object from its standard input, and its standard output is used to update the\nworktree file. Similarly, the clean command is used to convert the contents of worktree\nfile upon checkin. By default these commands process only a single blob and terminate. If\na long running process filter is used in place of clean and/or smudge filters, then Git\ncan process all blobs with a single filter command invocation for the entire life of a\nsingle Git command, for example git add --all. If a long running process filter is\nconfigured then it always takes precedence over a configured single blob filter. See\nsection below for the description of the protocol used to communicate with a process\nfilter.\n\nOne use of the content filtering is to massage the content into a shape that is more\nconvenient for the platform, filesystem, and the user to use. For this mode of operation,\nthe key phrase here is \"more convenient\" and not \"turning something unusable into\nusable\". In other words, the intent is that if someone unsets the filter driver\ndefinition, or does not have the appropriate filter program, the project should still be\nusable.\n\nAnother use of the content filtering is to store the content that cannot be directly used\nin the repository (e.g. a UUID that refers to the true content stored outside Git, or an\nencrypted content) and turn it into a usable form upon checkout (e.g. download the\nexternal content, or decrypt the encrypted content).\n\nThese two filters behave differently, and by default, a filter is taken as the former,\nmassaging the contents into more convenient shape. A missing filter driver definition in\nthe config, or a filter driver that exits with a non-zero status, is not an error but\nmakes the filter a no-op passthru.\n\nYou can declare that a filter turns a content that by itself is unusable into a usable\ncontent by setting the filter.<driver>.required configuration variable to true.\n\nNote: Whenever the clean filter is changed, the repo should be renormalized: $ git add\n--renormalize .\n\nFor example, in .gitattributes, you would assign the filter attribute for paths.\n\n*.c     filter=indent\n\n\nThen you would define a \"filter.indent.clean\" and \"filter.indent.smudge\" configuration in\nyour .git/config to specify a pair of commands to modify the contents of C programs when\nthe source files are checked in (\"clean\" is run) and checked out (no change is made\nbecause the command is \"cat\").\n\n[filter \"indent\"]\nclean = indent\nsmudge = cat\n\n\nFor best results, clean should not alter its output further if it is run twice\n(\"clean→clean\" should be equivalent to \"clean\"), and multiple smudge commands should not\nalter clean's output (\"smudge→smudge→clean\" should be equivalent to \"clean\"). See the\nsection on merging below.\n\nThe \"indent\" filter is well-behaved in this regard: it will not modify input that is\nalready correctly indented. In this case, the lack of a smudge filter means that the\nclean filter must accept its own output without modifying it.\n\nIf a filter must succeed in order to make the stored contents usable, you can declare\nthat the filter is required, in the configuration:\n\n[filter \"crypt\"]\nclean = openssl enc ...\nsmudge = openssl enc -d ...\nrequired\n\n\nSequence \"%f\" on the filter command line is replaced with the name of the file the filter\nis working on. A filter might use this in keyword substitution. For example:\n\n[filter \"p4\"]\nclean = git-p4-filter --clean %f\nsmudge = git-p4-filter --smudge %f\n\n\nNote that \"%f\" is the name of the path that is being worked on. Depending on the version\nthat is being filtered, the corresponding file on disk may not exist, or may have\ndifferent contents. So, smudge and clean commands should not try to access the file on\ndisk, but only act as filters on the content provided to them on standard input.\n"
                },
                {
                    "name": "Long Running Filter Process",
                    "content": "If the filter command (a string value) is defined via filter.<driver>.process then Git\ncan process all blobs with a single filter invocation for the entire life of a single Git\ncommand. This is achieved by using the long-running process protocol (described in\ntechnical/long-running-process-protocol.txt).\n\nWhen Git encounters the first file that needs to be cleaned or smudged, it starts the\nfilter and performs the handshake. In the handshake, the welcome message sent by Git is\n\"git-filter-client\", only version 2 is supported, and the supported capabilities are\n\"clean\", \"smudge\", and \"delay\".\n\nAfterwards Git sends a list of \"key=value\" pairs terminated with a flush packet. The list\nwill contain at least the filter command (based on the supported capabilities) and the\npathname of the file to filter relative to the repository root. Right after the flush\npacket Git sends the content split in zero or more pkt-line packets and a flush packet to\nterminate content. Please note, that the filter must not send any response before it\nreceived the content and the final flush packet. Also note that the \"value\" of a\n\"key=value\" pair can contain the \"=\" character whereas the key would never contain that\ncharacter.\n\npacket:          git> command=smudge\npacket:          git> pathname=path/testfile.dat\npacket:          git> 0000\npacket:          git> CONTENT\npacket:          git> 0000\n\n\nThe filter is expected to respond with a list of \"key=value\" pairs terminated with a\nflush packet. If the filter does not experience problems then the list must contain a\n\"success\" status. Right after these packets the filter is expected to send the content in\nzero or more pkt-line packets and a flush packet at the end. Finally, a second list of\n\"key=value\" pairs terminated with a flush packet is expected. The filter can change the\nstatus in the second list or keep the status as is with an empty list. Please note that\nthe empty list must be terminated with a flush packet regardless.\n\npacket:          git< status=success\npacket:          git< 0000\npacket:          git< SMUDGEDCONTENT\npacket:          git< 0000\npacket:          git< 0000  # empty list, keep \"status=success\" unchanged!\n\n\nIf the result content is empty then the filter is expected to respond with a \"success\"\nstatus and a flush packet to signal the empty content.\n\npacket:          git< status=success\npacket:          git< 0000\npacket:          git< 0000  # empty content!\npacket:          git< 0000  # empty list, keep \"status=success\" unchanged!\n\n\nIn case the filter cannot or does not want to process the content, it is expected to\nrespond with an \"error\" status.\n\npacket:          git< status=error\npacket:          git< 0000\n\n\nIf the filter experiences an error during processing, then it can send the status \"error\"\nafter the content was (partially or completely) sent.\n\npacket:          git< status=success\npacket:          git< 0000\npacket:          git< HALFWRITTENERRONEOUSCONTENT\npacket:          git< 0000\npacket:          git< status=error\npacket:          git< 0000\n\n\nIn case the filter cannot or does not want to process the content as well as any future\ncontent for the lifetime of the Git process, then it is expected to respond with an\n\"abort\" status at any point in the protocol.\n\npacket:          git< status=abort\npacket:          git< 0000\n\n\nGit neither stops nor restarts the filter process in case the \"error\"/\"abort\" status is\nset. However, Git sets its exit code according to the filter.<driver>.required flag,\nmimicking the behavior of the filter.<driver>.clean / filter.<driver>.smudge mechanism.\n\nIf the filter dies during the communication or does not adhere to the protocol then Git\nwill stop the filter process and restart it with the next file that needs to be\nprocessed. Depending on the filter.<driver>.required flag Git will interpret that as\nerror.\n"
                },
                {
                    "name": "Delay",
                    "content": "If the filter supports the \"delay\" capability, then Git can send the flag \"can-delay\"\nafter the filter command and pathname. This flag denotes that the filter can delay\nfiltering the current blob (e.g. to compensate network latencies) by responding with no\ncontent but with the status \"delayed\" and a flush packet.\n\npacket:          git> command=smudge\npacket:          git> pathname=path/testfile.dat\npacket:          git> can-delay=1\npacket:          git> 0000\npacket:          git> CONTENT\npacket:          git> 0000\npacket:          git< status=delayed\npacket:          git< 0000\n\n\nIf the filter supports the \"delay\" capability then it must support the\n\"listavailableblobs\" command. If Git sends this command, then the filter is expected to\nreturn a list of pathnames representing blobs that have been delayed earlier and are now\navailable. The list must be terminated with a flush packet followed by a \"success\" status\nthat is also terminated with a flush packet. If no blobs for the delayed paths are\navailable, yet, then the filter is expected to block the response until at least one blob\nbecomes available. The filter can tell Git that it has no more delayed blobs by sending\nan empty list. As soon as the filter responds with an empty list, Git stops asking. All\nblobs that Git has not received at this point are considered missing and will result in\nan error.\n\npacket:          git> command=listavailableblobs\npacket:          git> 0000\npacket:          git< pathname=path/testfile.dat\npacket:          git< pathname=path/otherfile.dat\npacket:          git< 0000\npacket:          git< status=success\npacket:          git< 0000\n\n\nAfter Git received the pathnames, it will request the corresponding blobs again. These\nrequests contain a pathname and an empty content section. The filter is expected to\nrespond with the smudged content in the usual way as explained above.\n\npacket:          git> command=smudge\npacket:          git> pathname=path/testfile.dat\npacket:          git> 0000\npacket:          git> 0000  # empty content!\npacket:          git< status=success\npacket:          git< 0000\npacket:          git< SMUDGEDCONTENT\npacket:          git< 0000\npacket:          git< 0000  # empty list, keep \"status=success\" unchanged!\n\n"
                },
                {
                    "name": "Example",
                    "content": "A long running filter demo implementation can be found in\ncontrib/long-running-filter/example.pl located in the Git core repository. If you develop\nyour own long running filter process then the GITTRACEPACKET environment variables can\nbe very helpful for debugging (see git(1)).\n\nPlease note that you cannot use an existing filter.<driver>.clean or\nfilter.<driver>.smudge command with filter.<driver>.process because the former two use a\ndifferent inter process communication protocol than the latter one.\n"
                },
                {
                    "name": "Interaction between checkin/checkout attributes",
                    "content": "In the check-in codepath, the worktree file is first converted with filter driver (if\nspecified and corresponding driver defined), then the result is processed with ident (if\nspecified), and then finally with text (again, if specified and applicable).\n\nIn the check-out codepath, the blob content is first converted with text, and then ident\nand fed to filter.\n"
                },
                {
                    "name": "Merging branches with differing checkin/checkout attributes",
                    "content": "If you have added attributes to a file that cause the canonical repository format for\nthat file to change, such as adding a clean/smudge filter or text/eol/ident attributes,\nmerging anything where the attribute is not in place would normally cause merge\nconflicts.\n\nTo prevent these unnecessary merge conflicts, Git can be told to run a virtual check-out\nand check-in of all three stages of a file when resolving a three-way merge by setting\nthe merge.renormalize configuration variable. This prevents changes caused by check-in\nconversion from causing spurious merge conflicts when a converted file is merged with an\nunconverted file.\n\nAs long as a \"smudge→clean\" results in the same output as a \"clean\" even on files that\nare already smudged, this strategy will automatically resolve all filter-related\nconflicts. Filters that do not act in this way may cause additional merge conflicts that\nmust be resolved manually.\n"
                },
                {
                    "name": "Generating diff text",
                    "content": ""
                },
                {
                    "name": "diff",
                    "content": "The attribute diff affects how Git generates diffs for particular files. It can tell Git\nwhether to generate a textual patch for the path or to treat the path as a binary file.\nIt can also affect what line is shown on the hunk header @@ -k,l +n,m @@ line, tell Git\nto use an external command to generate the diff, or ask Git to convert binary files to a\ntext format before generating the diff.\n\nSet\nA path to which the diff attribute is set is treated as text, even when they contain\nbyte values that normally never appear in text files, such as NUL.\n\nUnset\nA path to which the diff attribute is unset will generate Binary files differ (or a\nbinary patch, if binary patches are enabled).\n\nUnspecified\nA path to which the diff attribute is unspecified first gets its contents inspected,\nand if it looks like text and is smaller than core.bigFileThreshold, it is treated as\ntext. Otherwise it would generate Binary files differ.\n\nString\nDiff is shown using the specified diff driver. Each driver may specify one or more\noptions, as described in the following section. The options for the diff driver \"foo\"\nare defined by the configuration variables in the \"diff.foo\" section of the Git\nconfig file.\n"
                },
                {
                    "name": "Defining an external diff driver",
                    "content": "The definition of a diff driver is done in gitconfig, not gitattributes file, so strictly\nspeaking this manual page is a wrong place to talk about it. However...\n\nTo define an external diff driver jcdiff, add a section to your $GITDIR/config file (or\n$HOME/.gitconfig file) like this:\n\n[diff \"jcdiff\"]\ncommand = j-c-diff\n\n\nWhen Git needs to show you a diff for the path with diff attribute set to jcdiff, it\ncalls the command you specified with the above configuration, i.e. j-c-diff, with 7\nparameters, just like GITEXTERNALDIFF program is called. See git(1) for details.\n"
                },
                {
                    "name": "Defining a custom hunk-header",
                    "content": "Each group of changes (called a \"hunk\") in the textual diff output is prefixed with a\nline of the form:\n\n@@ -k,l +n,m @@ TEXT\n\nThis is called a hunk header. The \"TEXT\" portion is by default a line that begins with an\nalphabet, an underscore or a dollar sign; this matches what GNU diff -p output uses. This\ndefault selection however is not suited for some contents, and you can use a customized\npattern to make a selection.\n\nFirst, in .gitattributes, you would assign the diff attribute for paths.\n\n*.tex   diff=tex\n\n\nThen, you would define a \"diff.tex.xfuncname\" configuration to specify a regular\nexpression that matches a line that you would want to appear as the hunk header \"TEXT\".\nAdd a section to your $GITDIR/config file (or $HOME/.gitconfig file) like this:\n\n[diff \"tex\"]\nxfuncname = \"^(\\\\\\\\(sub)*section\\\\{.*)$\"\n\n\nNote. A single level of backslashes are eaten by the configuration file parser, so you\nwould need to double the backslashes; the pattern above picks a line that begins with a\nbackslash, and zero or more occurrences of sub followed by section followed by open\nbrace, to the end of line.\n\nThere are a few built-in patterns to make this easier, and tex is one of them, so you do\nnot have to write the above in your configuration file (you still need to enable this\nwith the attribute mechanism, via .gitattributes). The following built in patterns are\navailable:\n\n•   ada suitable for source code in the Ada language.\n\n•   bash suitable for source code in the Bourne-Again SHell language. Covers a superset\nof POSIX shell function definitions.\n\n•   bibtex suitable for files with BibTeX coded references.\n\n•   cpp suitable for source code in the C and C++ languages.\n\n•   csharp suitable for source code in the C# language.\n\n•   css suitable for cascading style sheets.\n\n•   dts suitable for devicetree (DTS) files.\n\n•   elixir suitable for source code in the Elixir language.\n\n•   fortran suitable for source code in the Fortran language.\n\n•   fountain suitable for Fountain documents.\n\n•   golang suitable for source code in the Go language.\n\n•   html suitable for HTML/XHTML documents.\n\n•   java suitable for source code in the Java language.\n\n•   markdown suitable for Markdown documents.\n\n•   matlab suitable for source code in the MATLAB and Octave languages.\n\n•   objc suitable for source code in the Objective-C language.\n\n•   pascal suitable for source code in the Pascal/Delphi language.\n\n•   perl suitable for source code in the Perl language.\n\n•   php suitable for source code in the PHP language.\n\n•   python suitable for source code in the Python language.\n\n•   ruby suitable for source code in the Ruby language.\n\n•   rust suitable for source code in the Rust language.\n\n•   scheme suitable for source code in the Scheme language.\n\n•   tex suitable for source code for LaTeX documents.\n"
                },
                {
                    "name": "Customizing word diff",
                    "content": "You can customize the rules that git diff --word-diff uses to split words in a line, by\nspecifying an appropriate regular expression in the \"diff.*.wordRegex\" configuration\nvariable. For example, in TeX a backslash followed by a sequence of letters forms a\ncommand, but several such commands can be run together without intervening whitespace. To\nseparate them, use a regular expression in your $GITDIR/config file (or $HOME/.gitconfig\nfile) like this:\n\n[diff \"tex\"]\nwordRegex = \"\\\\\\\\[a-zA-Z]+|[{}]|\\\\\\\\.|[^\\\\{}[:space:]]+\"\n\n\nA built-in pattern is provided for all languages listed in the previous section.\n"
                },
                {
                    "name": "Performing text diffs of binary files",
                    "content": "Sometimes it is desirable to see the diff of a text-converted version of some binary\nfiles. For example, a word processor document can be converted to an ASCII text\nrepresentation, and the diff of the text shown. Even though this conversion loses some\ninformation, the resulting diff is useful for human viewing (but cannot be applied\ndirectly).\n\nThe textconv config option is used to define a program for performing such a conversion.\nThe program should take a single argument, the name of a file to convert, and produce the\nresulting text on stdout.\n\nFor example, to show the diff of the exif information of a file instead of the binary\ninformation (assuming you have the exif tool installed), add the following section to\nyour $GITDIR/config file (or $HOME/.gitconfig file):\n\n[diff \"jpg\"]\ntextconv = exif\n\n\nNote\nThe text conversion is generally a one-way conversion; in this example, we lose the\nactual image contents and focus just on the text data. This means that diffs\ngenerated by textconv are not suitable for applying. For this reason, only git diff\nand the git log family of commands (i.e., log, whatchanged, show) will perform text\nconversion. git format-patch will never generate this output. If you want to send\nsomebody a text-converted diff of a binary file (e.g., because it quickly conveys the\nchanges you have made), you should generate it separately and send it as a comment in\naddition to the usual binary diff that you might send.\n\nBecause text conversion can be slow, especially when doing a large number of them with\ngit log -p, Git provides a mechanism to cache the output and use it in future diffs. To\nenable caching, set the \"cachetextconv\" variable in your diff driver’s config. For\nexample:\n\n[diff \"jpg\"]\ntextconv = exif\ncachetextconv = true\n\n\nThis will cache the result of running \"exif\" on each blob indefinitely. If you change the\ntextconv config variable for a diff driver, Git will automatically invalidate the cache\nentries and re-run the textconv filter. If you want to invalidate the cache manually\n(e.g., because your version of \"exif\" was updated and now produces better output), you\ncan remove the cache manually with git update-ref -d refs/notes/textconv/jpg (where \"jpg\"\nis the name of the diff driver, as in the example above).\n"
                },
                {
                    "name": "Choosing textconv versus external diff",
                    "content": "If you want to show differences between binary or specially-formatted blobs in your\nrepository, you can choose to use either an external diff command, or to use textconv to\nconvert them to a diff-able text format. Which method you choose depends on your exact\nsituation.\n\nThe advantage of using an external diff command is flexibility. You are not bound to find\nline-oriented changes, nor is it necessary for the output to resemble unified diff. You\nare free to locate and report changes in the most appropriate way for your data format.\n\nA textconv, by comparison, is much more limiting. You provide a transformation of the\ndata into a line-oriented text format, and Git uses its regular diff tools to generate\nthe output. There are several advantages to choosing this method:\n\n1. Ease of use. It is often much simpler to write a binary to text transformation than\nit is to perform your own diff. In many cases, existing programs can be used as\ntextconv filters (e.g., exif, odt2txt).\n\n2. Git diff features. By performing only the transformation step yourself, you can still\nutilize many of Git’s diff features, including colorization, word-diff, and combined\ndiffs for merges.\n\n3. Caching. Textconv caching can speed up repeated diffs, such as those you might\ntrigger by running git log -p.\n"
                },
                {
                    "name": "Marking files as binary",
                    "content": "Git usually guesses correctly whether a blob contains text or binary data by examining\nthe beginning of the contents. However, sometimes you may want to override its decision,\neither because a blob contains binary data later in the file, or because the content,\nwhile technically composed of text characters, is opaque to a human reader. For example,\nmany postscript files contain only ASCII characters, but produce noisy and meaningless\ndiffs.\n\nThe simplest way to mark a file as binary is to unset the diff attribute in the\n.gitattributes file:\n\n*.ps -diff\n\n\nThis will cause Git to generate Binary files differ (or a binary patch, if binary patches\nare enabled) instead of a regular diff.\n\nHowever, one may also want to specify other diff driver attributes. For example, you\nmight want to use textconv to convert postscript files to an ASCII representation for\nhuman viewing, but otherwise treat them as binary files. You cannot specify both -diff\nand diff=ps attributes. The solution is to use the diff.*.binary config option:\n\n[diff \"ps\"]\ntextconv = ps2ascii\nbinary = true\n\n"
                },
                {
                    "name": "Performing a three-way merge",
                    "content": ""
                },
                {
                    "name": "merge",
                    "content": "The attribute merge affects how three versions of a file are merged when a file-level\nmerge is necessary during git merge, and other commands such as git revert and git\ncherry-pick.\n\nSet\nBuilt-in 3-way merge driver is used to merge the contents in a way similar to merge\ncommand of RCS suite. This is suitable for ordinary text files.\n\nUnset\nTake the version from the current branch as the tentative merge result, and declare\nthat the merge has conflicts. This is suitable for binary files that do not have a\nwell-defined merge semantics.\n\nUnspecified\nBy default, this uses the same built-in 3-way merge driver as is the case when the\nmerge attribute is set. However, the merge.default configuration variable can name\ndifferent merge driver to be used with paths for which the merge attribute is\nunspecified.\n\nString\n3-way merge is performed using the specified custom merge driver. The built-in 3-way\nmerge driver can be explicitly specified by asking for \"text\" driver; the built-in\n\"take the current branch\" driver can be requested with \"binary\".\n"
                },
                {
                    "name": "Built-in merge drivers",
                    "content": "There are a few built-in low-level merge drivers defined that can be asked for via the\nmerge attribute.\n\ntext\nUsual 3-way file level merge for text files. Conflicted regions are marked with\nconflict markers <<<<<<<, ======= and >>>>>>>. The version from your branch appears\nbefore the ======= marker, and the version from the merged branch appears after the\n======= marker.\n\nbinary\nKeep the version from your branch in the work tree, but leave the path in the\nconflicted state for the user to sort out.\n\nunion\nRun 3-way file level merge for text files, but take lines from both versions, instead\nof leaving conflict markers. This tends to leave the added lines in the resulting\nfile in random order and the user should verify the result. Do not use this if you do\nnot understand the implications.\n"
                },
                {
                    "name": "Defining a custom merge driver",
                    "content": "The definition of a merge driver is done in the .git/config file, not in the\ngitattributes file, so strictly speaking this manual page is a wrong place to talk about\nit. However...\n\nTo define a custom merge driver filfre, add a section to your $GITDIR/config file (or\n$HOME/.gitconfig file) like this:\n\n[merge \"filfre\"]\nname = feel-free merge driver\ndriver = filfre %O %A %B %L %P\nrecursive = binary\n\n\nThe merge.*.name variable gives the driver a human-readable name.\n\nThe ‘merge.*.driver` variable’s value is used to construct a command to run to merge\nancestor’s version (%O), current version (%A) and the other branches’ version (%B). These\nthree tokens are replaced with the names of temporary files that hold the contents of\nthese versions when the command line is built. Additionally, %L will be replaced with the\nconflict marker size (see below).\n\nThe merge driver is expected to leave the result of the merge in the file named with %A\nby overwriting it, and exit with zero status if it managed to merge them cleanly, or\nnon-zero if there were conflicts.\n\nThe merge.*.recursive variable specifies what other merge driver to use when the merge\ndriver is called for an internal merge between common ancestors, when there are more than\none. When left unspecified, the driver itself is used for both internal merge and the\nfinal merge.\n\nThe merge driver can learn the pathname in which the merged result will be stored via\nplaceholder %P.\n"
                },
                {
                    "name": "conflict-marker-size",
                    "content": "This attribute controls the length of conflict markers left in the work tree file during\na conflicted merge. Only setting to the value to a positive integer has any meaningful\neffect.\n\nFor example, this line in .gitattributes can be used to tell the merge machinery to leave\nmuch longer (instead of the usual 7-character-long) conflict markers when merging the\nfile Documentation/git-merge.txt results in a conflict.\n\nDocumentation/git-merge.txt     conflict-marker-size=32\n\n"
                },
                {
                    "name": "Checking whitespace errors",
                    "content": ""
                },
                {
                    "name": "whitespace",
                    "content": "The core.whitespace configuration variable allows you to define what diff and apply\nshould consider whitespace errors for all paths in the project (See git-config(1)). This\nattribute gives you finer control per path.\n\nSet\nNotice all types of potential whitespace errors known to Git. The tab width is taken\nfrom the value of the core.whitespace configuration variable.\n\nUnset\nDo not notice anything as error.\n\nUnspecified\nUse the value of the core.whitespace configuration variable to decide what to notice\nas error.\n\nString\nSpecify a comma separate list of common whitespace problems to notice in the same\nformat as the core.whitespace configuration variable.\n"
                },
                {
                    "name": "Creating an archive",
                    "content": ""
                },
                {
                    "name": "export-ignore",
                    "content": "Files and directories with the attribute export-ignore won’t be added to archive files.\n"
                },
                {
                    "name": "export-subst",
                    "content": "If the attribute export-subst is set for a file then Git will expand several placeholders\nwhen adding this file to an archive. The expansion depends on the availability of a\ncommit ID, i.e., if git-archive(1) has been given a tree instead of a commit or a tag\nthen no replacement will be done. The placeholders are the same as those for the option\n--pretty=format: of git-log(1), except that they need to be wrapped like this:\n$Format:PLACEHOLDERS$ in the file. E.g. the string $Format:%H$ will be replaced by the\ncommit hash. However, only one %(describe) placeholder is expanded per archive to avoid\ndenial-of-service attacks.\n"
                },
                {
                    "name": "Packing objects",
                    "content": ""
                },
                {
                    "name": "delta",
                    "content": "Delta compression will not be attempted for blobs for paths with the attribute delta set\nto false.\n"
                },
                {
                    "name": "Viewing files in GUI tools",
                    "content": ""
                },
                {
                    "name": "encoding",
                    "content": "The value of this attribute specifies the character encoding that should be used by GUI\ntools (e.g. gitk(1) and git-gui(1)) to display the contents of the relevant file. Note\nthat due to performance considerations gitk(1) does not use this attribute unless you\nmanually enable per-file encodings in its options.\n\nIf this attribute is not set or has an invalid value, the value of the gui.encoding\nconfiguration variable is used instead (See git-config(1)).\n"
                }
            ]
        },
        "USING MACRO ATTRIBUTES": {
            "content": "You do not want any end-of-line conversions applied to, nor textual diffs produced for, any\nbinary file you track. You would need to specify e.g.\n\n*.jpg -text -diff\n\n\nbut that may become cumbersome, when you have many attributes. Using macro attributes, you\ncan define an attribute that, when set, also sets or unsets a number of other attributes at\nthe same time. The system knows a built-in macro attribute, binary:\n\n*.jpg binary\n\n\nSetting the \"binary\" attribute also unsets the \"text\" and \"diff\" attributes as above. Note\nthat macro attributes can only be \"Set\", though setting one might have the effect of setting\nor unsetting other attributes or even returning other attributes to the \"Unspecified\" state.\n",
            "subsections": []
        },
        "DEFINING MACRO ATTRIBUTES": {
            "content": "Custom macro attributes can be defined only in top-level gitattributes files\n($GITDIR/info/attributes, the .gitattributes file at the top level of the working tree, or\nthe global or system-wide gitattributes files), not in .gitattributes files in working tree\nsubdirectories. The built-in macro attribute \"binary\" is equivalent to:\n\n[attr]binary -diff -merge -text\n\n",
            "subsections": []
        },
        "NOTES": {
            "content": "Git does not follow symbolic links when accessing a .gitattributes file in the working tree.\nThis keeps behavior consistent when the file is accessed from the index or a tree versus from\nthe filesystem.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "If you have these three gitattributes file:\n\n(in $GITDIR/info/attributes)\n\na*      foo !bar -baz\n\n(in .gitattributes)\nabc     foo bar baz\n\n(in t/.gitattributes)\nab*     merge=filfre\nabc     -foo -bar\n*.c     frotz\n\n\nthe attributes given to path t/abc are computed as follows:\n\n1. By examining t/.gitattributes (which is in the same directory as the path in question),\nGit finds that the first line matches.  merge attribute is set. It also finds that the\nsecond line matches, and attributes foo and bar are unset.\n\n2. Then it examines .gitattributes (which is in the parent directory), and finds that the\nfirst line matches, but t/.gitattributes file already decided how merge, foo and bar\nattributes should be given to this path, so it leaves foo and bar unset. Attribute baz is\nset.\n\n3. Finally it examines $GITDIR/info/attributes. This file is used to override the in-tree\nsettings. The first line is a match, and foo is set, bar is reverted to unspecified\nstate, and baz is unset.\n\nAs the result, the attributes assignment to t/abc becomes:\n\nfoo     set to true\nbar     unspecified\nbaz     set to false\nmerge   set to string value \"filfre\"\nfrotz   unspecified\n\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "git-check-attr(1).\n",
            "subsections": []
        },
        "GIT": {
            "content": "Part of the git(1) suite\n\n\n\nGit 2.34.1                                   02/26/2026                             GITATTRIBUTES(5)",
            "subsections": []
        }
    },
    "summary": "gitattributes - Defining attributes per path",
    "flags": [],
    "examples": [
        "If you have these three gitattributes file:",
        "(in $GITDIR/info/attributes)",
        "a*      foo !bar -baz",
        "(in .gitattributes)",
        "abc     foo bar baz",
        "(in t/.gitattributes)",
        "ab*     merge=filfre",
        "abc     -foo -bar",
        "*.c     frotz",
        "the attributes given to path t/abc are computed as follows:",
        "1. By examining t/.gitattributes (which is in the same directory as the path in question),",
        "Git finds that the first line matches.  merge attribute is set. It also finds that the",
        "second line matches, and attributes foo and bar are unset.",
        "2. Then it examines .gitattributes (which is in the parent directory), and finds that the",
        "first line matches, but t/.gitattributes file already decided how merge, foo and bar",
        "attributes should be given to this path, so it leaves foo and bar unset. Attribute baz is",
        "set.",
        "3. Finally it examines $GITDIR/info/attributes. This file is used to override the in-tree",
        "settings. The first line is a match, and foo is set, bar is reverted to unspecified",
        "state, and baz is unset.",
        "As the result, the attributes assignment to t/abc becomes:",
        "foo     set to true",
        "bar     unspecified",
        "baz     set to false",
        "merge   set to string value \"filfre\"",
        "frotz   unspecified"
    ],
    "see_also": [
        {
            "name": "git-check-attr",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/git-check-attr/1/json"
        }
    ]
}