File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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:
182184The 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+
185200SEE ALSO
186201--------
187202linkgit:git-rm[1],
You can’t perform that action at this time.
0 commit comments