`git add .` 和 `git add -u` 之间有什么区别?

发布于 2024-08-19 22:35:14 字数 96 浏览 7 评论 0原文

我假设两者的工作方式相同。两者都将每个文件添加到索引中。但我好像错了。

  • git add . 和 git add -u 之间有什么区别?

I was assuming that both work in the same way. Both add every file onto index. But I seem wrong.

  • What's the difference between git add . and git add -u?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

辞别 2024-08-26 22:35:14

这是这里提到的 git 陷阱之一(Git 2.0 之前)。

git add . 仅添加现有内容,而不添加已删除的内容(如果已跟踪)。

git add .
git commit
git status
//hey! why didn't it commit my deletes?, Oh yeah, silly me
git add -u .
git commit --amend

git add -A 将处理这两个步骤...


使用 Git 2.0,git add -A 为默认

git add 现在与“git add -A”相同,因此
git add dir/”会注意到您从目录中删除的路径,并且
记录移除情况。
在旧版本的 Git 中,“git add”用于忽略删除。

您可以说“git add --ignore-removal
如果您确实愿意,则仅在 中添加添加或修改的路径。


警告(git1.8.3 2013 年 4 月,对于即将推出的 git2.0)。
我已将答案修改为 git add -u .,而不是 git add -u

git add -u 将在 Git 2.0 中对整个树进行操作,以与“git commit -a”和其他命令保持一致。
因为没有机制可以使“git add -u”表现得像“git add -u .”,所以
对于那些习惯于“git add -u”(不带路径规范)仅更新当前子目录中的路径的索引以开始训练手指明确地说“git add -u”的人来说很重要.”,他们在 Git 2.0 出现之前就已经这么说了。

正如我在“e”中提到的

It is one of the git gotchas mentioned here (pre Git 2.0).

git add . only adds what is there, not what has been deleted (if tracked).

git add .
git commit
git status
//hey! why didn't it commit my deletes?, Oh yeah, silly me
git add -u .
git commit --amend

git add -A would take care of both steps...


With Git 2.0, git add -A is default.

git add <path> is the same as "git add -A <path>" now, so that
"git add dir/" will notice paths you removed from the directory and
record the removal.
In older versions of Git, "git add <path>" used to ignore removals.

You can say "git add --ignore-removal <path>" to
add only added or modified paths in <path>, if you really want to.


Warning (git1.8.3 April 2013, for upcoming git2.0).
I have modified my answer to say git add -u ., instead of git add -u.:

git add -u will operate on the entire tree in Git 2.0 for consistency with "git commit -a" and other commands.
Because there will be no mechanism to make "git add -u" behave as "git add -u .", it is
important for those who are used to "git add -u" (without pathspec) updating the index only for paths in the current subdirectory to start training their fingers to explicitly say "git add -u ." when they mean it before Git 2.0 comes.

As I mentioned in "e"

葬花如无物 2024-08-26 22:35:14

就像手册所说: git add . 会添加当前目录中的所有文件,而 git add -u . 只会添加那些已经被跟踪的文件。

Like the manual says: git add . will add all files in the current directory, whereas git add -u . will only add those already being tracked.

只为一人 2024-08-26 22:35:14

git add documentaiton

git add . 

添加当前目录中的所有文件

git add -u 

仅 更新当前正在跟踪的文件。

git add documentaiton

git add . 

add all files from the current directory

git add -u 

only update files currently being tracked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文