3

有没有办法在 git 中跟踪被 .gitignore 中存在的规则排除的新文件?我想在我的 .gitignore 规则中不添加单个文件/目录排除项来执行此操作。

4

2 回答 2

6

好吧,我很难找到答案,但老实说我还没有尝试过。结果是在 .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'会起作用:

git add -f Test.exe
于 2013-04-12T19:40:16.590 回答
2
Use -f if you really want to add them.

使用 Git 2.26(2020 年第一季度),这现在是一个“提示”,当“ git add”注意到用户没有添加任何内容时,会通过两条新的帮助消息进行控制。

这意味着,确保git config advice.addIgnoredFile未设置为true(默认情况下确实如此:其默认值为false),否则您不会意识到git add -f这里需要 a 。

请参阅提交 887a0fd(2020 年 2 月 6 日)和提交 bf66db3(2020 年 1 月 7 日),作者是Heba Waly ( HebaWaly)
(由Junio C Hamano 合并 -- gitster--提交 daef1b3中,2020 年 2 月 14 日)

add:更改添加 API 使用的建议配置变量

签字人:Heba Waly

advice.addNothingconfig 变量用于控制添加库中两条建议消息的可见性。
这个 config 变量被两个新变量替换,它们的名称更清晰并且与这两种情况相关。

还将这两个新变量添加到文档中。

  • addIgnoredFile
    如果用户尝试将忽略的文件添加到索引中,则会显示建议。
  • addEmptyPathspec
    如果用户在不提供 pathspec 参数的情况下运行 add 命令,则会显示建议。

现在的提示是:

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"
于 2020-02-15T21:40:45.133 回答