gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:19:50 24 4
gpt4 key购买 nike

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

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.

通过“将被忽略”,我假设如果“git add -n”没有显示它将对存在的文件执行的操作,那么该文件将被“忽略”。我还没有想出命令会字面上显示文件将被忽略的情况……但是。请注意,我在过去几周才开始使用 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您的 .gitignore 文件之一忽略了以下路径”消息和非零退出状态。即使实际上没有名为 some.filename 的文件,这仍然有效。如果没有 --ignore-missing,您将收到有关 some.filename 不存在的错误消息。

关于git - git add -n --ignore-missing 实际上做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39150038/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com