`git add .`和`git add -u`有什么区别? [英] What's the difference between `git add .` and `git add -u`?

查看:265
本文介绍了`git add .`和`git add -u`有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我假设两者都以相同的方式工作。都将每个文件添加到索引。但我认为是错误的。


  • git add。 git add -u


解决方案

它是这里提到的中的一个git陷阱 (pre Git 2.0)。



git add。只会增加那里的内容,而不会删除已被删除的内容(if跟踪)。

  git add。 
git commit
git status
//嘿!为什么它没有提交我的删除?哦,是的,傻我
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<路径> to
add只有在<路径> 中添加或修改过路径,如果您真的想要。







警告( 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 的用户而言,它是
pathspec)仅更新当前子目录中的路径的索引以开始训练其fin gers在Git 2.0出现之前明确表示 git add -u。


正如我在 e 中所述


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?

解决方案

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"

这篇关于`git add .`和`git add -u`有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆