git add ., git add -A 和 git add -u 之间的区别

Difference between git add ., git add -A and git add -u

以下命令有什么区别?

我尝试执行它们,它们产生了相同的结果。

git help add

   -A, --all, --no-ignore-removal
       Update the index not only where the working tree has a file matching <pathspec> but also where the index already has an
       entry. This adds, modifies, and removes index entries to match the working tree.

       If no <pathspec> is given, the current version of Git defaults to "."; in other words, update all files in the current
       directory and its subdirectories. This default will change in a future version of Git, hence the form without <pathspec>
       should not be used.

   -u, --update
       Update the index just where it already has an entry matching <pathspec>. This removes as well as modifies index entries to
       match the working tree, but adds no new files.

       If no <pathspec> is given, the current version of Git defaults to "."; in other words, update all tracked files in the
       current directory and its subdirectories. This default will change in a future version of Git, hence the form without
       <pathspec> should not be used.
  • .-A-u 隐含,如果没有给出 <pathspec> (您的问题就是这种情况)。
  • -A 将暂存更改、删除的文件和添加的文件。
  • -u 将暂存更改和删除的文件,但 不会 添加文件。