git add .、git add -A 和 git add -u 之间的区别 [重复]

Posted

技术标签:

【中文标题】git add .、git add -A 和 git add -u 之间的区别 [重复]【英文标题】:Difference between git add ., git add -A and git add -u [duplicate] 【发布时间】:2018-07-09 22:09:05 【问题描述】:

以下命令有什么区别?

git 添加。 git add -A git add -u

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

【问题讨论】:

之前找不到那个重复的。 【参考方案1】:

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.
如果没有给出&lt;pathspec&gt;(你的问题就是这种情况),-A-u 都暗示了.-A 将暂存更改、删除文件和添加文件。 -u 将暂存更改并删除文件,但添加文件。

【讨论】:

Git 2.0和更早的版本Git 1.X没有区别吗?

以上是关于git add .、git add -A 和 git add -u 之间的区别 [重复]的主要内容,如果未能解决你的问题,请参考以下文章

Git 学习记录

git 文件操作

git篇之add

git 常用命令

git add 回退 和 git commit 回退

git add 回退 和 git commit 回退