Skip to content

Commit 59856de

Browse files
kbleesgitster
authored andcommitted
gitignore.txt: clarify recursive nature of excluded directories
Additionally, precedence of negated patterns is exactly as outlined in the DESCRIPTION section, we don't need to repeat this. Signed-off-by: Karsten Blees <blees@dcon.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8447dc8 commit 59856de

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Documentation/gitignore.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ PATTERN FORMAT
7979

8080
- An optional prefix "`!`" which negates the pattern; any
8181
matching file excluded by a previous pattern will become
82-
included again. If a negated pattern matches, this will
83-
override lower precedence patterns sources.
82+
included again. It is not possible to re-include a file if a parent
83+
directory of that file is excluded. Git doesn't list excluded
84+
directories for performance reasons, so any patterns on contained
85+
files have no effect, no matter where they are defined.
8486
Put a backslash ("`\`") in front of the first "`!`" for patterns
8587
that begin with a literal "`!`", for example, "`\!important!.txt`".
8688

@@ -182,6 +184,19 @@ Another example:
182184
The second .gitignore prevents Git from ignoring
183185
`arch/foo/kernel/vmlinux.lds.S`.
184186

187+
Example to exclude everything except a specific directory `foo/bar`
188+
(note the `/*` - without the slash, the wildcard would also exclude
189+
everything within `foo/bar`):
190+
191+
--------------------------------------------------------------
192+
$ cat .gitignore
193+
# exclude everything except directory foo/bar
194+
/*
195+
!/foo
196+
/foo/*
197+
!/foo/bar
198+
--------------------------------------------------------------
199+
185200
SEE ALSO
186201
--------
187202
linkgit:git-rm[1],

0 commit comments

Comments
 (0)