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

标签 git git-add

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

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

最佳答案

它是 git 陷阱之一 mentioned here(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 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.


警告(git1.8.3 April 2013, for upcoming git2.0)。
我修改了我的答案,说 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.
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.

正如我在“e”中提到的

关于git - `git add .` 和 `git add -u` 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2190409/

相关文章:

git - 我如何 git 仅添加与模式匹配的行?

java - EGit - "Replace With Commit..."无法正常工作

git - "git add -A"和 "git add ."之间的区别

git - 为什么有人应该在 git commit 之前使用 git add?或者为什么有人应该使用 git add ?

git - 在 git rm 文件之后;提交——如何从远程分支取回文件?

git - 如何使用 GitHub V3 API 获取 repo 的提交计数?

php - 对使用 git 在 openshift 服务器上部署应用程序感到困惑

macos - 如何在 macOS 上模拟 "sort -V"

git - "FATAL: Error computing merge base"是什么意思?

git - git add * 和 git add . 之间有什么区别(如果有的话)?