什么是“!”在 gitignore 文件中做什么?
what does "!" do in gitignore files?
这个我不太明白
我已经从 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".
我有这个 gitignore 文件
/media/*
!/media/xmlconnect
这到底是做什么的?我忽略了 /media/
中的所有子目录,但我是否对 /media/xmlconnect
进行了例外处理(例如,我没有忽略它?)
所以基本上我忽略了除 media/xmlconnect
之外的所有内容?
确切地说,这用于取消忽略在该行之前被忽略的路径。您的示例很好地说明了用例。
您忽略了除 xmlconnect 之外的媒体内的所有内容。
/media/*
以上忽略media中的所有文件
但是,如果您想例外并且不想忽略 media/xmlconnect,那么您可以使用 !
。
!/media/xmlconnect
当您执行 git add .
时,只会将 media/xmlconnect 添加到 git,不会添加媒体中的其他所有其他文件。
已编辑:颠倒顺序。git忽略:
Git applies patterns in .gitignore in order of appearance
,所以如果我们颠倒顺序
!/media/xmlconnect
在/media/*
之前,会忽略media目录下的所有文件。
您可以查看此 issue 以了解建议的修复。
这个我不太明白
我已经从 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".
我有这个 gitignore 文件
/media/*
!/media/xmlconnect
这到底是做什么的?我忽略了 /media/
中的所有子目录,但我是否对 /media/xmlconnect
进行了例外处理(例如,我没有忽略它?)
所以基本上我忽略了除 media/xmlconnect
之外的所有内容?
确切地说,这用于取消忽略在该行之前被忽略的路径。您的示例很好地说明了用例。
您忽略了除 xmlconnect 之外的媒体内的所有内容。
/media/*
以上忽略media中的所有文件
但是,如果您想例外并且不想忽略 media/xmlconnect,那么您可以使用 !
。
!/media/xmlconnect
当您执行 git add .
时,只会将 media/xmlconnect 添加到 git,不会添加媒体中的其他所有其他文件。
已编辑:颠倒顺序。git忽略:
Git applies patterns in .gitignore in order of appearance
,所以如果我们颠倒顺序
!/media/xmlconnect
在/media/*
之前,会忽略media目录下的所有文件。
您可以查看此 issue 以了解建议的修复。