Brent Goodrick <bgoodr@xxxxxxxxx> writes: > Say I have these files and directories [2]: > > /home/smart_tator/misc_files/.gitignore > /home/smart_tator/misc_files/foo/ > /home/smart_tator/misc_files/bar/ > /home/smart_tator/misc_files/bar/baz/foo/ > /home/smart_tator/misc_files/bar/baz/real/ > > then I do: > > cd /home/smart_tator/misc_files/; git init > > and say I have this line in that .gitignore file: > > foo/ > > And then I naively execute: > > git add bar/ > > then the bar/baz/real/ is added, but these are dutifully ignored: > > /home/smart_tator/misc_files/foo/ > /home/smart_tator/misc_files/bar/baz/foo/ I think you are looking for "/foo/". From Documentation/gitignore.txt: - If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, `foo/` will match a directory `foo` and paths underneath it, but will not match a regular file or a symbolic link `foo` (this is consistent with the way how pathspec works in general in git). With this rule, (1) the trailing slash in your "foo/" tells git to match only with directories, but (2) it behaves as if you said "foo" for all the other rules. With "/foo/", you tell git to match only with a directory, and it is as if you said "/foo". - If the pattern does not contain a slash '/', git treats it as a shell glob pattern and checks for a match against the pathname without leading directories. Your "foo/" now behaves the same way as "foo" behaves. You are telling git to match directory foo anywhere in the tree. "/foo/" (now behaving the same way as "/foo") does not satisfy this criteria so we would skip this rule. - Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, "Documentation/\*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html". A leading slash matches the beginning of the pathname; for example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c". Your "foo/" does not survive to this rule, but "/foo/" does. It now behaves as "/foo" and its leading slash makes it match the beginning. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html