[英]What's the difference between `git add .` and `git add -u`?
I was assuming that both work in the same way.我假设两者都以相同的方式工作。 Both add every file onto index.两者都将每个文件添加到索引中。 But I seem wrong.但我好像错了。
git add .
git add .
什么区别git add .
and git add -u
?和git add -u
?It is one of the git gotchas mentioned here (pre Git 2.0).这是这里提到的 git 陷阱之一(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... git add -A
会处理这两个步骤......
With Git 2.0, git add -A
is default .对于Git 2.0, git add -A
是默认值。
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.git add <path>
现在与“git add -A <path>
”相同,因此“git add dir/
”会注意到您从目录中删除的路径并记录删除。
In older versions of Git, "git add <path>
" used to ignore removals.在旧版本的 Git 中,“git add <path>
”用于忽略删除。You can say "
git add --ignore-removal <path>
" to add only added or modified paths in<path>
, if you really want to.如果您真的想要,您可以说“git add --ignore-removal <path>
”以仅在<path>
添加添加或修改的路径。
Warning ( git1.8.3 April 2013, for upcoming git2.0 ).警告( git1.8.3 April 2013,对于即将推出的 git2.0 )。
I have modified my answer to say git add -u .
我已经修改了我的答案说git add -u .
, instead of git add -u
.: , 而不是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.git add -u
将在 Git 2.0 中对整个树进行操作,以与“git commit -a
”和其他命令保持一致。
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.因为没有机制让“git add -u
”表现得像“git add -u .
”,所以对于那些习惯于“git add -u
”(没有路径规范)更新索引的人来说很重要当前子目录开始训练他们的手指明确地说“git add -u .
当他们在 Git 2.0 出现之前的意思时。
Like the manual says: git add .
就像手册上说的: git add .
will add all files in the current directory, whereas git add -u .
将添加当前目录中的所有文件,而git add -u .
will only add those already being tracked.只会添加那些已经被跟踪的。
git add documentaiton git 添加文档
git add .
add all files from the current directory添加当前目录中的所有文件
git add -u
only update files currently being tracked.仅更新当前正在跟踪的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.