Update Git docs to 2.29.2
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / gitignore.xml
blob1a52691b9ead5b12e2f2bb7b1e00f1af7fabdc90
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">\r
3 \r
4 <sect2 lang="en" id="gitignore(5)">\r
5     <title>gitignore(5)</title>\r
6 <indexterm>\r
7 <primary>gitignore(5)</primary>\r
8 </indexterm>\r
9 <simplesect id="gitignore(5)__name">\r
10 <title>NAME</title>\r
11 <simpara>gitignore - Specifies intentionally untracked files to ignore</simpara>\r
12 </simplesect>\r
13 <simplesect id="gitignore(5)__synopsis">\r
14 <title>SYNOPSIS</title>\r
15 <simpara>$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore</simpara>\r
16 </simplesect>\r
17 <simplesect id="gitignore(5)__description">\r
18 <title>DESCRIPTION</title>\r
19 <simpara>A <emphasis>gitignore</emphasis> file specifies intentionally untracked files that\r
20 Git should ignore.\r
21 Files already tracked by Git are not affected; see the NOTES\r
22 below for details.</simpara>\r
23 <simpara>Each line in a <emphasis>gitignore</emphasis> file specifies a pattern.\r
24 When deciding whether to ignore a path, Git normally checks\r
25 <emphasis>gitignore</emphasis> patterns from multiple sources, with the following\r
26 order of precedence, from highest to lowest (within one level of\r
27 precedence, the last matching pattern decides the outcome):</simpara>\r
28 <itemizedlist>\r
29 <listitem>\r
30 <simpara>\r
31 Patterns read from the command line for those commands that support\r
32    them.\r
33 </simpara>\r
34 </listitem>\r
35 <listitem>\r
36 <simpara>\r
37 Patterns read from a <emphasis>.gitignore</emphasis> file in the same directory\r
38    as the path, or in any parent directory, with patterns in the\r
39    higher level files (up to the toplevel of the work tree) being overridden\r
40    by those in lower level files down to the directory containing the file.\r
41    These patterns match relative to the location of the\r
42    <emphasis>.gitignore</emphasis> file.  A project normally includes such\r
43    <emphasis>.gitignore</emphasis> files in its repository, containing patterns for\r
44    files generated as part of the project build.\r
45 </simpara>\r
46 </listitem>\r
47 <listitem>\r
48 <simpara>\r
49 Patterns read from <emphasis>$GIT_DIR/info/exclude</emphasis>.\r
50 </simpara>\r
51 </listitem>\r
52 <listitem>\r
53 <simpara>\r
54 Patterns read from the file specified by the configuration\r
55    variable <emphasis>core.excludesFile</emphasis>.\r
56 </simpara>\r
57 </listitem>\r
58 </itemizedlist>\r
59 <simpara>Which file to place a pattern in depends on how the pattern is meant to\r
60 be used.</simpara>\r
61 <itemizedlist>\r
62 <listitem>\r
63 <simpara>\r
64 Patterns which should be version-controlled and distributed to\r
65    other repositories via clone (i.e., files that all developers will want\r
66    to ignore) should go into a <emphasis>.gitignore</emphasis> file.\r
67 </simpara>\r
68 </listitem>\r
69 <listitem>\r
70 <simpara>\r
71 Patterns which are\r
72    specific to a particular repository but which do not need to be shared\r
73    with other related repositories (e.g., auxiliary files that live inside\r
74    the repository but are specific to one user's workflow) should go into\r
75    the <emphasis>$GIT_DIR/info/exclude</emphasis> file.\r
76 </simpara>\r
77 </listitem>\r
78 <listitem>\r
79 <simpara>\r
80 Patterns which a user wants Git to\r
81    ignore in all situations (e.g., backup or temporary files generated by\r
82    the user's editor of choice) generally go into a file specified by\r
83    <emphasis>core.excludesFile</emphasis> in the user's <emphasis>~/.gitconfig</emphasis>. Its default value is\r
84    $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or\r
85    empty, $HOME/.config/git/ignore is used instead.\r
86 </simpara>\r
87 </listitem>\r
88 </itemizedlist>\r
89 <simpara>The underlying Git plumbing tools, such as\r
90 <emphasis>git ls-files</emphasis> and <emphasis>git read-tree</emphasis>, read\r
91 <emphasis>gitignore</emphasis> patterns specified by command-line options, or from\r
92 files specified by command-line options.  Higher-level Git\r
93 tools, such as <emphasis>git status</emphasis> and <emphasis>git add</emphasis>,\r
94 use patterns from the sources specified above.</simpara>\r
95 </simplesect>\r
96 <simplesect id="gitignore(5)__pattern_format">\r
97 <title>PATTERN FORMAT</title>\r
98 <itemizedlist>\r
99 <listitem>\r
100 <simpara>\r
101 A blank line matches no files, so it can serve as a separator\r
102    for readability.\r
103 </simpara>\r
104 </listitem>\r
105 <listitem>\r
106 <simpara>\r
107 A line starting with # serves as a comment.\r
108    Put a backslash ("<emphasis>\</emphasis>") in front of the first hash for patterns\r
109    that begin with a hash.\r
110 </simpara>\r
111 </listitem>\r
112 <listitem>\r
113 <simpara>\r
114 Trailing spaces are ignored unless they are quoted with backslash\r
115    ("<emphasis>\</emphasis>").\r
116 </simpara>\r
117 </listitem>\r
118 <listitem>\r
119 <simpara>\r
120 An optional prefix "<emphasis>!</emphasis>" which negates the pattern; any\r
121    matching file excluded by a previous pattern will become\r
122    included again. It is not possible to re-include a file if a parent\r
123    directory of that file is excluded. Git doesn't list excluded\r
124    directories for performance reasons, so any patterns on contained\r
125    files have no effect, no matter where they are defined.\r
126    Put a backslash ("<emphasis>\</emphasis>") in front of the first "<emphasis>!</emphasis>" for patterns\r
127    that begin with a literal "<emphasis>!</emphasis>", for example, "<emphasis>\!important!.txt</emphasis>".\r
128 </simpara>\r
129 </listitem>\r
130 <listitem>\r
131 <simpara>\r
132 The slash <emphasis>/</emphasis> is used as the directory separator. Separators may\r
133    occur at the beginning, middle or end of the <emphasis>.gitignore</emphasis> search pattern.\r
134 </simpara>\r
135 </listitem>\r
136 <listitem>\r
137 <simpara>\r
138 If there is a separator at the beginning or middle (or both) of the\r
139    pattern, then the pattern is relative to the directory level of the\r
140    particular <emphasis>.gitignore</emphasis> file itself. Otherwise the pattern may also\r
141    match at any level below the <emphasis>.gitignore</emphasis> level.\r
142 </simpara>\r
143 </listitem>\r
144 <listitem>\r
145 <simpara>\r
146 If there is a separator at the end of the pattern then the pattern\r
147    will only match directories, otherwise the pattern can match both\r
148    files and directories.\r
149 </simpara>\r
150 </listitem>\r
151 <listitem>\r
152 <simpara>\r
153 For example, a pattern <emphasis>doc/frotz/</emphasis> matches <emphasis>doc/frotz</emphasis> directory,\r
154    but not <emphasis>a/doc/frotz</emphasis> directory; however <emphasis>frotz/</emphasis> matches <emphasis>frotz</emphasis>\r
155    and <emphasis>a/frotz</emphasis> that is a directory (all paths are relative from\r
156    the <emphasis>.gitignore</emphasis> file).\r
157 </simpara>\r
158 </listitem>\r
159 <listitem>\r
160 <simpara>\r
161 An asterisk "<emphasis>*</emphasis>" matches anything except a slash.\r
162    The character "<emphasis>?</emphasis>" matches any one character except "<emphasis>/</emphasis>".\r
163    The range notation, e.g. <emphasis>[a-zA-Z]</emphasis>, can be used to match\r
164    one of the characters in a range. See fnmatch(3) and the\r
165    FNM_PATHNAME flag for a more detailed description.\r
166 </simpara>\r
167 </listitem>\r
168 </itemizedlist>\r
169 <simpara>Two consecutive asterisks ("<emphasis>**</emphasis>") in patterns matched against\r
170 full pathname may have special meaning:</simpara>\r
171 <itemizedlist>\r
172 <listitem>\r
173 <simpara>\r
174 A leading "<emphasis>**</emphasis>" followed by a slash means match in all\r
175    directories. For example, "<emphasis>**/foo</emphasis>" matches file or directory\r
176    "<emphasis>foo</emphasis>" anywhere, the same as pattern "<emphasis>foo</emphasis>". "<emphasis>**/foo/bar</emphasis>"\r
177    matches file or directory "<emphasis>bar</emphasis>" anywhere that is directly\r
178    under directory "<emphasis>foo</emphasis>".\r
179 </simpara>\r
180 </listitem>\r
181 <listitem>\r
182 <simpara>\r
183 A trailing "<emphasis>/**</emphasis>" matches everything inside. For example,\r
184    "<emphasis>abc/**</emphasis>" matches all files inside directory "<emphasis>abc</emphasis>", relative\r
185    to the location of the <emphasis>.gitignore</emphasis> file, with infinite depth.\r
186 </simpara>\r
187 </listitem>\r
188 <listitem>\r
189 <simpara>\r
190 A slash followed by two consecutive asterisks then a slash\r
191    matches zero or more directories. For example, "<emphasis>a/**/b</emphasis>"\r
192    matches "<emphasis>a/b</emphasis>", "<emphasis>a/x/b</emphasis>", "<emphasis>a/x/y/b</emphasis>" and so on.\r
193 </simpara>\r
194 </listitem>\r
195 <listitem>\r
196 <simpara>\r
197 Other consecutive asterisks are considered regular asterisks and\r
198    will match according to the previous rules.\r
199 </simpara>\r
200 </listitem>\r
201 </itemizedlist>\r
202 </simplesect>\r
203 <simplesect id="gitignore(5)__configuration">\r
204 <title>CONFIGURATION</title>\r
205 <simpara>The optional configuration variable <emphasis>core.excludesFile</emphasis> indicates a path to a\r
206 file containing patterns of file names to exclude, similar to\r
207 <emphasis>$GIT_DIR/info/exclude</emphasis>.  Patterns in the exclude file are used in addition to\r
208 those in <emphasis>$GIT_DIR/info/exclude</emphasis>.</simpara>\r
209 </simplesect>\r
210 <simplesect id="gitignore(5)__notes">\r
211 <title>NOTES</title>\r
212 <simpara>The purpose of gitignore files is to ensure that certain files\r
213 not tracked by Git remain untracked.</simpara>\r
214 <simpara>To stop tracking a file that is currently tracked, use\r
215 <emphasis>git rm --cached</emphasis>.</simpara>\r
216 </simplesect>\r
217 <simplesect id="gitignore(5)__examples">\r
218 <title>EXAMPLES</title>\r
219 <itemizedlist>\r
220 <listitem>\r
221 <simpara>\r
222 The pattern <emphasis>hello.*</emphasis> matches any file or folder\r
223    whose name begins with <emphasis>hello</emphasis>. If one wants to restrict\r
224    this only to the directory and not in its subdirectories,\r
225    one can prepend the pattern with a slash, i.e. <emphasis>/hello.*</emphasis>;\r
226    the pattern now matches <emphasis>hello.txt</emphasis>, <emphasis>hello.c</emphasis> but not\r
227    <emphasis>a/hello.java</emphasis>.\r
228 </simpara>\r
229 </listitem>\r
230 <listitem>\r
231 <simpara>\r
232 The pattern <emphasis>foo/</emphasis> will match a directory <emphasis>foo</emphasis> and\r
233    paths underneath it, but will not match a regular file\r
234    or a symbolic link <emphasis>foo</emphasis> (this is consistent with the\r
235    way how pathspec works in general in Git)\r
236 </simpara>\r
237 </listitem>\r
238 <listitem>\r
239 <simpara>\r
240 The pattern <emphasis>doc/frotz</emphasis> and <emphasis>/doc/frotz</emphasis> have the same effect\r
241    in any <emphasis>.gitignore</emphasis> file. In other words, a leading slash\r
242    is not relevant  if there is already a middle slash in\r
243    the pattern.\r
244 </simpara>\r
245 </listitem>\r
246 <listitem>\r
247 <simpara>\r
248 The pattern "foo/*", matches "foo/test.json"\r
249    (a regular file), "foo/bar" (a directory), but it does not match\r
250    "foo/bar/hello.c" (a regular file), as the asterisk in the\r
251    pattern does not match "bar/hello.c" which has a slash in it.\r
252 </simpara>\r
253 </listitem>\r
254 </itemizedlist>\r
255 <screen>    $ git status\r
256     [...]\r
257     # Untracked files:\r
258     [...]\r
259     #       Documentation/foo.html\r
260     #       Documentation/gitignore.html\r
261     #       file.o\r
262     #       lib.a\r
263     #       src/internal.o\r
264     [...]\r
265     $ cat .git/info/exclude\r
266     # ignore objects and archives, anywhere in the tree.\r
267     *.[oa]\r
268     $ cat Documentation/.gitignore\r
269     # ignore generated html files,\r
270     *.html\r
271     # except foo.html which is maintained by hand\r
272     !foo.html\r
273     $ git status\r
274     [...]\r
275     # Untracked files:\r
276     [...]\r
277     #       Documentation/foo.html\r
278     [...]</screen>\r
279 <simpara>Another example:</simpara>\r
280 <screen>    $ cat .gitignore\r
281     vmlinux*\r
282     $ ls arch/foo/kernel/vm*\r
283     arch/foo/kernel/vmlinux.lds.S\r
284     $ echo '!/vmlinux*' &gt;arch/foo/kernel/.gitignore</screen>\r
285 <simpara>The second .gitignore prevents Git from ignoring\r
286 <emphasis>arch/foo/kernel/vmlinux.lds.S</emphasis>.</simpara>\r
287 <simpara>Example to exclude everything except a specific directory <emphasis>foo/bar</emphasis>\r
288 (note the <emphasis>/*</emphasis> - without the slash, the wildcard would also exclude\r
289 everything within <emphasis>foo/bar</emphasis>):</simpara>\r
290 <screen>    $ cat .gitignore\r
291     # exclude everything except directory foo/bar\r
292     /*\r
293     !/foo\r
294     /foo/*\r
295     !/foo/bar</screen>\r
296 </simplesect>\r
297 <simplesect id="gitignore(5)__see_also">\r
298 <title>SEE ALSO</title>\r
299 <simpara><xref linkend="git-rm(1)" />,\r
300 <xref linkend="gitrepository-layout(5)" />,\r
301 <xref linkend="git-check-ignore(1)" /></simpara>\r
302 </simplesect>\r
303 <simplesect id="gitignore(5)__git">\r
304 <title>GIT</title>\r
305 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
306 </simplesect>\r
307 </sect2>\r