Git 是否更改了“!” .gitignore 的前缀行为?
Did Git change the "!" prefix behavior at .gitignore?
我在 Git 2.7 发行说明中找到了下面的一句话。
Allow a later "!/abc/def" to override an earlier "/abc" that
appears in the same .gitignore file to make it easier to express
"everything in /abc directory is ignored, except for ...".
不过,此功能在后续版本中似乎无效
$ git --version
git version 2.19.1
$ cat .gitignore
/abc
!/abc/def
$ mkdir abc
$ echo foo > abc/def
$ git status
On branch master
nothing to commit, working tree clean
是否Git改变了“!” .gitignore 的前缀行为?还是我记错了?
看起来该更改已在 2.8.0 中恢复,为什么您要梳理两年前的发行说明以查看 gitignore 的行为方式,而您只需说 git help ignore
它就会告诉您
- 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".
如果你不想忽略目录修剪,那么执行 gitignores 的简单方法是忽略它们的全部内容
directory/**
之后是任何覆盖,(例如你的 !directory/def
)和你的 gitignore put
的末尾
!*/
后跟您真正想要的任何完全排除。
我在 Git 2.7 发行说明中找到了下面的一句话。
Allow a later "!/abc/def" to override an earlier "/abc" that appears in the same .gitignore file to make it easier to express "everything in /abc directory is ignored, except for ...".
不过,此功能在后续版本中似乎无效
$ git --version
git version 2.19.1
$ cat .gitignore
/abc
!/abc/def
$ mkdir abc
$ echo foo > abc/def
$ git status
On branch master
nothing to commit, working tree clean
是否Git改变了“!” .gitignore 的前缀行为?还是我记错了?
看起来该更改已在 2.8.0 中恢复,为什么您要梳理两年前的发行说明以查看 gitignore 的行为方式,而您只需说 git help ignore
它就会告诉您
- 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".
如果你不想忽略目录修剪,那么执行 gitignores 的简单方法是忽略它们的全部内容
directory/**
之后是任何覆盖,(例如你的 !directory/def
)和你的 gitignore put
!*/
后跟您真正想要的任何完全排除。