Skip to content

Commit f963371

Browse files
committed
Merge branch 'kb/doc-exclude-directory-semantics'
* kb/doc-exclude-directory-semantics: gitignore.txt: clarify recursive nature of excluded directories
2 parents d7aced9 + 59856de commit f963371

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)