.gitignore规则

A blank line matches no files, so it can serve as a separator for readability.
空行不表示匹配,可用于分割,便于可读。


A line starting with # serves as a comment. Put a backslash (“\”) in front of the first hash for patterns that begin with a hash.
#开头的是注释,如果要在开头使用#号,要转义\#


Trailing spaces are ignored unless they are quoted with backslash (“\”).
两端的空格可以忽略。


An optional prefix “!” which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash (“\”) in front of the first “!” for patterns that begin with a literal “!”, for example, “!important!.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).
如果结尾有/,则表示只匹配目录。比如,a/表示a是目录。


If the pattern does not contain a slash /, Git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).
如果不包含/,则会全局匹配。比如a,匹配任何目录下的a


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” or “tools/perf/Documentation/perf.html”.
通配符*不能跨目录。


A leading slash matches the beginning of the pathname. For example, “/*.c” matches “cat-file.c” but not “mozilla-sha1/sha1.c”.
如果开头有/,则表示匹配根目录。比如,/a表示根目录下的a


Two consecutive asterisks (“**”) in patterns matched against full pathname may have special meaning:
两个星号**

A leading “” followed by a slash means match in all directories. For example, “/foo” matches file or directory “foo” anywhere, the same as pattern “foo”. “**/foo/bar” matches file or directory “bar” anywhere that is directly under directory “foo”.
比如**/a,表示任何目录下的a


A trailing “/” matches everything inside. For example, “abc/” matches all files inside directory “abc”, relative to the location of the .gitignore file, with infinite depth.
比如abc/**,递归匹配abc下的所有文件和目录。


A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, “a/**/b” matches “a/b”, “a/x/b”, “a/x/y/b” and so on.
比如a/**/b,其中的**表示0到多层目录。


Other consecutive asterisks are considered invalid.
其他情况下的两个*属于无效用法

参考

[1] https://git-scm.com/docs/gitignore

你可能感兴趣的:(Git)