updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / gitignore.xml
blob71fe8f7c52ae207c96d18a6ba458a2b3dee38f56
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <article lang="en" id="gitignore(5)">\r
5 <articleinfo>\r
6     <title>gitignore(5)</title>\r
7 <indexterm>\r
8 <primary>gitignore(5)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>gitignore - Specifies intentionally untracked files to ignore</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <simpara>$GIT_DIR/info/exclude, .gitignore</simpara>\r
18 </simplesect>\r
19 <simplesect id="_description">\r
20 <title>DESCRIPTION</title>\r
21 <simpara>A <emphasis>gitignore</emphasis> file specifies intentionally untracked files that\r
22 git should ignore.\r
23 Files already tracked by git are not affected; see the NOTES\r
24 below for details.</simpara>\r
25 <simpara>Each line in a <emphasis>gitignore</emphasis> file specifies a pattern.\r
26 When deciding whether to ignore a path, git normally checks\r
27 <emphasis>gitignore</emphasis> patterns from multiple sources, with the following\r
28 order of precedence, from highest to lowest (within one level of\r
29 precedence, the last matching pattern decides the outcome):</simpara>\r
30 <itemizedlist>\r
31 <listitem>\r
32 <simpara>\r
33 Patterns read from the command line for those commands that support\r
34    them.\r
35 </simpara>\r
36 </listitem>\r
37 <listitem>\r
38 <simpara>\r
39 Patterns read from a <emphasis>.gitignore</emphasis> file in the same directory\r
40    as the path, or in any parent directory, with patterns in the\r
41    higher level files (up to the toplevel of the work tree) being overridden\r
42    by those in lower level files down to the directory containing the file.\r
43    These patterns match relative to the location of the\r
44    <emphasis>.gitignore</emphasis> file.  A project normally includes such\r
45    <emphasis>.gitignore</emphasis> files in its repository, containing patterns for\r
46    files generated as part of the project build.\r
47 </simpara>\r
48 </listitem>\r
49 <listitem>\r
50 <simpara>\r
51 Patterns read from <emphasis>$GIT_DIR/info/exclude</emphasis>.\r
52 </simpara>\r
53 </listitem>\r
54 <listitem>\r
55 <simpara>\r
56 Patterns read from the file specified by the configuration\r
57    variable <emphasis>core.excludesfile</emphasis>.\r
58 </simpara>\r
59 </listitem>\r
60 </itemizedlist>\r
61 <simpara>Which file to place a pattern in depends on how the pattern is meant to\r
62 be used. Patterns which should be version-controlled and distributed to\r
63 other repositories via clone (i.e., files that all developers will want\r
64 to ignore) should go into a <emphasis>.gitignore</emphasis> file. Patterns which are\r
65 specific to a particular repository but which do not need to be shared\r
66 with other related repositories (e.g., auxiliary files that live inside\r
67 the repository but are specific to one user's workflow) should go into\r
68 the <emphasis>$GIT_DIR/info/exclude</emphasis> file.  Patterns which a user wants git to\r
69 ignore in all situations (e.g., backup or temporary files generated by\r
70 the user's editor of choice) generally go into a file specified by\r
71 <emphasis>core.excludesfile</emphasis> in the user's <emphasis>~/.gitconfig</emphasis>.</simpara>\r
72 <simpara>The underlying git plumbing tools, such as\r
73 <emphasis>git ls-files</emphasis> and <emphasis>git read-tree</emphasis>, read\r
74 <emphasis>gitignore</emphasis> patterns specified by command-line options, or from\r
75 files specified by command-line options.  Higher-level git\r
76 tools, such as <emphasis>git status</emphasis> and <emphasis>git add</emphasis>,\r
77 use patterns from the sources specified above.</simpara>\r
78 </simplesect>\r
79 <simplesect id="_pattern_format">\r
80 <title>PATTERN FORMAT</title>\r
81 <itemizedlist>\r
82 <listitem>\r
83 <simpara>\r
84 A blank line matches no files, so it can serve as a separator\r
85    for readability.\r
86 </simpara>\r
87 </listitem>\r
88 <listitem>\r
89 <simpara>\r
90 A line starting with # serves as a comment.\r
91 </simpara>\r
92 </listitem>\r
93 <listitem>\r
94 <simpara>\r
95 An optional prefix <emphasis>!</emphasis> which negates the pattern; any\r
96    matching file excluded by a previous pattern will become\r
97    included again.  If a negated pattern matches, this will\r
98    override lower precedence patterns sources.\r
99 </simpara>\r
100 </listitem>\r
101 <listitem>\r
102 <simpara>\r
103 If the pattern ends with a slash, it is removed for the\r
104    purpose of the following description, but it would only find\r
105    a match with a directory.  In other words, <emphasis>foo/</emphasis> will match a\r
106    directory <emphasis>foo</emphasis> and paths underneath it, but will not match a\r
107    regular file or a symbolic link <emphasis>foo</emphasis> (this is consistent\r
108    with the way how pathspec works in general in git).\r
109 </simpara>\r
110 </listitem>\r
111 <listitem>\r
112 <simpara>\r
113 If the pattern does not contain a slash <emphasis>/</emphasis>, git treats it as\r
114    a shell glob pattern and checks for a match against the\r
115    pathname relative to the location of the <emphasis>.gitignore</emphasis> file\r
116    (relative to the toplevel of the work tree if not from a\r
117    <emphasis>.gitignore</emphasis> file).\r
118 </simpara>\r
119 </listitem>\r
120 <listitem>\r
121 <simpara>\r
122 Otherwise, git treats the pattern as a shell glob suitable\r
123    for consumption by fnmatch(3) with the FNM_PATHNAME flag:\r
124    wildcards in the pattern will not match a / in the pathname.\r
125    For example, "Documentation/&#42;.html" matches\r
126    "Documentation/git.html" but not "Documentation/ppc/ppc.html"\r
127    or "tools/perf/Documentation/perf.html".\r
128 </simpara>\r
129 </listitem>\r
130 <listitem>\r
131 <simpara>\r
132 A leading slash matches the beginning of the pathname.\r
133    For example, "/&#42;.c" matches "cat-file.c" but not\r
134    "mozilla-sha1/sha1.c".\r
135 </simpara>\r
136 </listitem>\r
137 </itemizedlist>\r
138 </simplesect>\r
139 <simplesect id="_notes">\r
140 <title>NOTES</title>\r
141 <simpara>The purpose of gitignore files is to ensure that certain files\r
142 not tracked by git remain untracked.</simpara>\r
143 <simpara>To ignore uncommitted changes in a file that is already tracked,\r
144 use <emphasis>git update-index &#45;&#45;assume-unchanged</emphasis>.</simpara>\r
145 <simpara>To stop tracking a file that is currently tracked, use\r
146 <emphasis>git rm --cached</emphasis>.</simpara>\r
147 </simplesect>\r
148 <simplesect id="_examples">\r
149 <title>EXAMPLES</title>\r
150 <screen>    $ git status\r
151     [...]\r
152     # Untracked files:\r
153     [...]\r
154     #       Documentation/foo.html\r
155     #       Documentation/gitignore.html\r
156     #       file.o\r
157     #       lib.a\r
158     #       src/internal.o\r
159     [...]\r
160     $ cat .git/info/exclude\r
161     # ignore objects and archives, anywhere in the tree.\r
162     *.[oa]\r
163     $ cat Documentation/.gitignore\r
164     # ignore generated html files,\r
165     *.html\r
166     # except foo.html which is maintained by hand\r
167     !foo.html\r
168     $ git status\r
169     [...]\r
170     # Untracked files:\r
171     [...]\r
172     #       Documentation/foo.html\r
173     [...]</screen>\r
174 <simpara>Another example:</simpara>\r
175 <screen>    $ cat .gitignore\r
176     vmlinux*\r
177     $ ls arch/foo/kernel/vm*\r
178     arch/foo/kernel/vmlinux.lds.S\r
179     $ echo '!/vmlinux*' &gt;arch/foo/kernel/.gitignore</screen>\r
180 <simpara>The second .gitignore prevents git from ignoring\r
181 <emphasis>arch/foo/kernel/vmlinux.lds.S</emphasis>.</simpara>\r
182 </simplesect>\r
183 <simplesect id="_see_also">\r
184 <title>SEE ALSO</title>\r
185 <simpara><xref linkend="git-rm(1)" />, <xref linkend="git-update-index(1)" />,\r
186 <xref linkend="gitrepository-layout(5)" /></simpara>\r
187 </simplesect>\r
188 <simplesect id="_git">\r
189 <title>GIT</title>\r
190 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
191 </simplesect>\r
192 </article>\r