git过滤所有名称为xxx的目录
使用背景:某项目中需要过滤所有名称为abcd的文件夹。
在.ignore文件中使用“abcd/”这样的方式只能过滤当前目录的abcd目录,对子目录或者更深层级的目录无效。
查资料发现可以使用这样的方法:/**/abcd。这样可以过滤掉所有名为abcd的目录,包括这些目录下的子目录和子文件。
参考内容:
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 trailing "
/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the.gitignorefile, with infinite depth. -
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. -
Other consecutive asterisks are considered invalid.
参考文档:
https://mirrors.edge.kernel.org/pub/software/scm/git/docs/gitignore.html

浙公网安备 33010602011771号