Skip to content

Commit 30b0535

Browse files
author
Junio C Hamano
committed
Documentation: describe git-ls-files --exclude patterns.
Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent f87f949 commit 30b0535

File tree

1 file changed

+92
-4
lines changed

1 file changed

+92
-4
lines changed

Documentation/git-ls-files.txt

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SYNOPSIS
1414
(-[c|d|o|i|s|u|k])\*
1515
[-x <pattern>|--exclude=<pattern>]
1616
[-X <file>|--exclude-from=<file>]
17+
[--exclude-per-directory=<file>]
1718

1819
DESCRIPTION
1920
-----------
@@ -59,10 +60,10 @@ OPTIONS
5960

6061
-X|--exclude-from=<file>::
6162
exclude patterns are read from <file>; 1 per line.
62-
Allows the use of the famous dontdiff file as follows to find
63-
out about uncommitted files just as dontdiff is used with
64-
the diff command:
65-
git-ls-files --others --exclude-from=dontdiff
63+
64+
--exclude-per-directory=<file>::
65+
read additional exclude patterns that apply only to the
66+
directory and its subdirectories in <file>.
6667

6768
-t::
6869
Identify the file status with the following tags (followed by
@@ -89,6 +90,93 @@ the dircache records up to three such pairs; one from tree O in stage
8990
the user (or Cogito) to see what should eventually be recorded at the
9091
path. (see read-cache for more information on state)
9192

93+
94+
Exclude Patterns
95+
----------------
96+
97+
'git-ls-files' can use a list of "exclude patterns" when
98+
traversing the directory tree and finding files to show when the
99+
flags --others or --ignored are specified.
100+
101+
These exclude patterns come from these places:
102+
103+
(1) command line flag --exclude=<pattern> specifies a single
104+
pattern.
105+
106+
(2) command line flag --exclude-from=<file> specifies a list of
107+
patterns stored in a file.
108+
109+
(3) command line flag --exclude-per-directory=<name> specifies
110+
a name of the file in each directory 'git-ls-files'
111+
examines, and if exists, its contents are used as an
112+
additional list of patterns.
113+
114+
An exclude pattern file used by (2) and (3) contains one pattern
115+
per line. A line that starts with a '#' can be used as comment
116+
for readability.
117+
118+
The list of patterns that is in effect at a given time is
119+
built and ordered in the following way:
120+
121+
* --exclude=<pattern> and lines read from --exclude-from=<file>
122+
come at the beginning of the list of patterns, in the order
123+
given on the command line. Patterns that come from the file
124+
specified with --exclude-from are ordered in the same order
125+
as they appear in the file.
126+
127+
* When --exclude-per-directory=<name> is specified, upon
128+
entering a directory that has such a file, its contents are
129+
appended at the end of the current "list of patterns". They
130+
are popped off when leaving the directory.
131+
132+
Each pattern in the pattern list specifies "a match pattern" and
133+
optionally the fate --- either a file that matches the pattern
134+
is considered excluded or included. By default, this being
135+
"exclude" mechanism, the fate is "excluded". A filename is
136+
examined against the patterns in the list, and the first match
137+
determines its fate.
138+
139+
A pattern specified on the command line with --exclude or read
140+
from the file specified with --exclude-from is relative to the
141+
top of the directory tree. A pattern read from a file specified
142+
by --exclude-per-directory is relative to the directory that the
143+
pattern file appears in.
144+
145+
An exclude pattern is of the following format:
146+
147+
- an optional prefix '!' which means that the fate this pattern
148+
specifies is "include", not the usual "exclude"; the
149+
remainder of the pattern string is interpreted according to
150+
the following rules.
151+
152+
- if it does not contain a slash '/', it is a shell glob
153+
pattern and used to match against the filename without
154+
leading directories (i.e. the same way as the current
155+
implementation).
156+
157+
- otherwise, it is a shell glob pattern, suitable for
158+
consumption by fnmatch(3) with FNM_PATHNAME flag. I.e. a
159+
slash in the pattern must match a slash in the pathname.
160+
"Documentation/*.html" matches "Documentation/git.html" but
161+
not "ppc/ppc.html". As a natural exception, "/*.c" matches
162+
"cat-file.c" but not "mozilla-sha1/sha1.c".
163+
164+
An example:
165+
166+
$ cat .git/ignore
167+
# ignore objects and archives, anywhere in the tree.
168+
*.[oa]
169+
$ cat Documentation/.gitignore
170+
# ignore generated html files,
171+
# except foo.html which is maintained by hand
172+
!foo.html
173+
*.html
174+
$ git-ls-files --ignored \
175+
--exclude='Documentation/*.[0-9]' \
176+
--exclude-from=.git/ignore \
177+
--exclude-per-directory=.gitignore
178+
179+
92180
See Also
93181
--------
94182
link:read-cache.html[read-cache]

0 commit comments

Comments
 (0)