.gitignore
行有其特定的解释规则。
https://linux.die.net/man/5/gitignore
• A blank line matches no files, so it can serve as a separator for readability.
• A line starting with # serves as a comment.
• An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.
• 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).
• 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.
• 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".
其他工具也使用相同的规则,例如npm的files
中的package.json
键需要相同的格式。
此模式有名称吗?或者最合适的名字是什么?
答案 0 :(得分:2)
这些规则的另一个正式文档在git-scm
文档中。
我认为.gitignore
最接近的事物是glob
pattern matching,他们在某些文档中提到了这一点:
如果模式不包含斜杠/,则git会将其视为 shell glob模式,并检查是否与路径名匹配,且不带前导目录。
但是,这并不完全相同,这就是它们指定规则的原因。