git add -n --ignore-missing 实际上做了什么?

What does git add -n --ignore-missing actually do?

这看起来很简单,但我很难理解以下命令之间的区别:

git add -n 
and
git add -n --ignore-missing

我相信我理解 "git add -n" 的作用,因为它是 "git add" 的干燥 运行,这意味着它将告诉用户将添加哪些文件更改暂存区(索引),实际上没有向暂存区添加任何内容。我在online git documentation中阅读了"git add -n"命令的以下描述:

-n
--dry-run

Don’t actually add the file(s), just show if they exist and/or will be ignored.

"will be ignored" 我假设如果 "git add -n" 没有显示它将对存在的文件执行的操作,那么该文件正在 "ignored"。我还没有想出命令会字面上显示文件将被忽略的情况……但是。请注意,过去几周我一直在与 Git 合作。

现在,我的困惑开始于“--ignore-missing”的以下描述:

--ignore-missing

This option can only be used together with --dry-run. By using this option the user can check if any of the given files would be ignored, no matter if they are already present in the work tree or not.

“...用户可以检查是否会忽略任何给定的文件”...但是,我认为这就是 "git add -n" 本身所做的。我设置了一个存储库,其中所有匹配 *.log 的文件都将被忽略。然而,我没有看到 "git add -n" 提及任何具有该扩展名的文件,除非它已经是存储库的一部分。 "git add -n --ignore-missing".

也是如此

我一直在拼命寻找一种方法,让这个选项与 "git add -n" 的常规用法有所不同。我觉得我对 "git add -n" 的理解部分或完全不正确,这让我很担心。所以我希望有人能详细说明并强调我哪里出错了。感谢所有能提供帮助的人!

您可以 git add -n --ignore-missing some.filename,如果 some.filename 被 gitignore 策略忽略,您将收到 "The following paths are ignored by one of your .gitignore files" 消息和非零退出状态。即使实际上没有名为 some.filename 的文件,这仍然有效 。如果没有 --ignore-missing,您将收到有关 some.filename 不存在的错误消息。