First, it's worth mentioning a tricky bit about ignore file patterns: if they contain a leading or an embedded slash, they apply across multiple name components, but if they do not, they apply to one name component (in whatever directory Git is traversing, recursively, at the time). This rule gets applied after removing a trailing slash if there is one, so that a .gitignore
file that contains:
abc
def/ghi
ignores all files (and directories) named abc
that occur from this point "downward", while ignoring only def/ghi
that occurs at this point. The second line is exactly equivalent to /def/ghi
.
Can I set git to use full paths in ignoring something?
No. Gitignore patterns are either relative to the directory in which the ignore file occurs (for most .gitignore
files) or the project root (for .git/info/exclude
and your personal ignore file). That is, suppose the project lives in /home/arron/project/proj1
and:
$ cd ~/project/proj1/
$ cat .gitignore
/abc
sub/file
$ cat sub/.gitignore
/dir/
All of these entries contain or begin with /
, so the top level .gitignore
suppresses complaints about the untracked file abc
in the top level of the project plus complaints about the untracked file file
in the directory sub
. Meanwhile the directory sub
has its own .gitignore
that not only suppresses complaints about, but stops Git from even enumerating the contents of, the directory dir
within sub
, i.e., Git does not look inside project/proj1/sub/dir/
at all (hence neither discovers, nor complains about, any untracked files within that directory).
Note that if we modify both .gitignore
files so that we have instead:
$ cat .gitignore
/abc
$ cat sub/.gitignore
/file
/dir/
the set of ignored files remains exactly the same.