Git 忽略除 certian 目录之外的目录
Git Ignore a dir except certian dir's
我一直在努力理解 git 模式格式,以免忽略 node_modules
中的某些常见目录
我有 20 多个目录,它们都共享相同的三个字符,我正在尝试找出一种模式来从 gitignore
中排除这些目录
例子
node_modules
|
|apifoo
|apibar
|apix
|..
|..
.
https://git-scm.com/docs/gitignore
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".
所以像 !node_modules/api*
避免将 node_modules 作为目录排除,而是排除它的所有文件!
因为如@markus 所说排除目录不会让 git 注意该目录中的任何规则。
排除 node_modules 就像 node_modules/
这不是你想要的,在你的情况下你想告诉 git:请排除 node_modules 目录中的所有文件而不是 node_modules 它自己,这可以通过 node_modules/*
来实现,然后添加一个否定以包含 !/node_modules/apihawk*/
以 api 开头的任何目录
我一直在努力理解 git 模式格式,以免忽略 node_modules
中的某些常见目录我有 20 多个目录,它们都共享相同的三个字符,我正在尝试找出一种模式来从 gitignore
中排除这些目录例子
node_modules
|
|apifoo
|apibar
|apix
|..
|..
.
https://git-scm.com/docs/gitignore
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".
所以像 !node_modules/api*
避免将 node_modules 作为目录排除,而是排除它的所有文件! 因为如@markus 所说排除目录不会让 git 注意该目录中的任何规则。
排除 node_modules 就像 node_modules/
这不是你想要的,在你的情况下你想告诉 git:请排除 node_modules 目录中的所有文件而不是 node_modules 它自己,这可以通过 node_modules/*
来实现,然后添加一个否定以包含 !/node_modules/apihawk*/