有没有一种方法可以跟踪一个在.gitignore文件中被排除的新文件呢?我想做到这一点,而又不想在我的.gitignore规则中添加任何单个文件/目录排除。
我曾经很难找到这个问题的答案,但说实话,我还没有尝试过。结果发现,在.gitignore中排除的文件上运行'git add'(如下所示)即可:
git add Test.exe
输出以下内容:
The following paths are ignored by one of your .gitignore files:
Test.exe
Use -f if you really want to add them.
fatal: no files added
git add -f Test.exe
在Git 2.26(2020年第一季度)中,这现在是一个“提示”,当“git add”注意到用户没有给出任何内容时,控制着两条新的帮助消息。Use -f if you really want to add them.
请查看 2020年2月6日提交887a0fd 和 2020年1月7日提交bf66db3,作者为Heba Waly (HebaWaly
)。
(由Junio C Hamano -- gitster
--合并于2020年2月14日提交daef1b3)
add
: 更改 add API 使用的建议配置变量签名:Heba Waly
advice.addNothing
配置变量用于控制 add 库中两个建议消息的可见性。
此配置变量已被两个新变量所取代,它们的名称更加清晰和相关于这两种情况。
同时将这两个新变量添加到文档中。
addIgnoredFile
:addEmptyPathspec
:现在的提示为:
Use -f if you really want to add them.
Turn this message off by running
"git config advice.addIgnoredFile false"
并且:
Maybe you wanted to say 'git add .'?
Turn this message off by running
"git config advice.addEmptyPathspec false"
.gitignore
会更好。您可以通过在.gitignore
中添加!Test.exe
来取消忽略文件。但这是您的存储库 - 您的规则 :) - acc15