Meaning of leading slash in `.gitignore` file
(The man pages I have found have hidden this information carefully.)
One Solution collect form web for “Meaning of leading slash in `.gitignore` file”
This is the documentation text:
- A leading slash matches the beginning of the pathname. For example, “/*.c” matches “cat-file.c”
but not “mozilla-sha1/sha1.c”.
These are my guesses:
If you use an in-repository-
.gitignore, the directory in which the
is located – it is not really useful to make it relative to the repository root.
A short experiment with same-named files in the repository root and a subdirectory (and a
.gitignorein this same directory) confirms this.
If you use an
core.excludesfile, I suppose it is relative
to the repository root.
Also this is (for info/exclude) confirmed by the same test (both tests on 184.108.40.206).
Schnouki found the right part of the documentation about this (emphasis mine):
- Patterns read from a
.gitignorefile in the same directory as the path, or in
any parent directory, with patterns in the higher level files (up to the toplevel
of the work tree) being overridden by those in lower level files down to the
directory containing the file. These patterns match relative to the location of
.gitignorefile. A project normally includes such
.gitignorefiles in its
repository, containing patterns for files generated as part of the project build.
One could say that this fact could have been repeated again at the later part quoted above, for clarity.