139
140
'git-ls-files' can use a list of "exclude patterns" when
141
traversing the directory tree and finding files to show when the
142
-flags --others or --ignored are specified.
142
+flags --others or --ignored are specified. gitlink:gitignore[5]
143
+specifies the format of exclude patterns.
144
144
-These exclude patterns come from these places:
145
+These exclude patterns come from these places, in order:
146
146
- 1. command line flag --exclude=<pattern> specifies a single
147
- pattern.
147
+ 1. The command line flag --exclude=<pattern> specifies a
148
+ single pattern. Patterns are ordered in the same order
149
+ they appear in the command line.
150
149
- 2. command line flag --exclude-from=<file> specifies a list of
150
- patterns stored in a file.
151
+ 2. The command line flag --exclude-from=<file> specifies a
152
+ file containing a list of patterns. Patterns are ordered
153
+ in the same order they appear in the file.
154
155
3. command line flag --exclude-per-directory=<name> specifies
156
a name of the file in each directory 'git-ls-files'
154
- examines, and if exists, its contents are used as an
155
- additional list of patterns.
156
-
157
-An exclude pattern file used by (2) and (3) contains one pattern
158
-per line. A line that starts with a '#' can be used as comment
159
-for readability.
160
-
161
-There are three lists of patterns that are in effect at a given
162
-time. They are built and ordered in the following way:
163
-
164
- * --exclude=<pattern> from the command line; patterns are
165
- ordered in the same order as they appear on the command line.
166
-
167
- * lines read from --exclude-from=<file>; patterns are ordered
168
- in the same order as they appear in the file.
169
-
170
- * When --exclude-per-directory=<name> is specified, upon
171
- entering a directory that has such a file, its contents are
172
- appended at the end of the current "list of patterns". They
173
- are popped off when leaving the directory.
174
-
175
-Each pattern in the pattern list specifies "a match pattern" and
176
-optionally the fate; either a file that matches the pattern is
177
-considered excluded or included. A filename is matched against
178
-the patterns in the three lists; the --exclude-from list is
179
-checked first, then the --exclude-per-directory list, and then
180
-finally the --exclude list. The last match determines its fate.
181
-If there is no match in the three lists, the fate is "included".
157
+ examines, normally `.gitignore`. Files in deeper
158
+ directories take precedence. Patterns are ordered in the
159
+ same order they appear in the files.
160
161
A pattern specified on the command line with --exclude or read
162
from the file specified with --exclude-from is relative to the
164
by --exclude-per-directory is relative to the directory that the
165
pattern file appears in.
166
189
-An exclude pattern is of the following format:
190
-
191
- - an optional prefix '!' which means that the fate this pattern
192
- specifies is "include", not the usual "exclude"; the
193
- remainder of the pattern string is interpreted according to
194
- the following rules.
195
-
196
- - if it does not contain a slash '/', it is a shell glob
197
- pattern and used to match against the filename without
198
- leading directories.
199
-
200
- - otherwise, it is a shell glob pattern, suitable for
201
- consumption by fnmatch(3) with FNM_PATHNAME flag. I.e. a
202
- slash in the pattern must match a slash in the pathname.
203
- "Documentation/\*.html" matches "Documentation/git.html" but
204
- not "ppc/ppc.html". As a natural exception, "/*.c" matches
205
- "cat-file.c" but not "mozilla-sha1/sha1.c".
206
-
207
-An example:
208
-
209
---------------------------------------------------------------
210
- $ cat .git/info/exclude
211
- # ignore objects and archives, anywhere in the tree.
212
- *.[oa]
213
- $ cat Documentation/.gitignore
214
- # ignore generated html files,
215
- *.html
216
- # except foo.html which is maintained by hand
217
- !foo.html
218
- $ git-ls-files --ignored \
219
- --exclude='Documentation/*.[0-9]' \
220
- --exclude-from=.git/info/exclude \
221
- --exclude-per-directory=.gitignore
222
---------------------------------------------------------------
223
-
224
-Another example:
225
-
226
---------------------------------------------------------------
227
- $ cat .gitignore
228
- vmlinux*
229
- $ ls arch/foo/kernel/vm*
230
- arch/foo/kernel/vmlinux.lds.S
231
- $ echo '!/vmlinux*' >arch/foo/kernel/.gitignore
232
---------------------------------------------------------------
233
-
234
-The second .gitignore keeps `arch/foo/kernel/vmlinux.lds.S` file
235
-from getting ignored.
236
-
237
-
167
See Also
168
--------
240
-gitlink:git-read-tree[1]
169
+gitlink:git-read-tree[1], gitlink:gitignore[5]
170
171
172
Author
175
176
Documentation
177
--------------
249
-Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>.
178
+Documentation by David Greaves, Junio C Hamano, Josh Triplett, and the git-list <git@vger.kernel.org>.
179
180
GIT
181
---