git-add[-all|-A]和git-add.之间有什么区别。?


当前回答

Git版本1.x

Command New Files Modified Files Deleted Files Description
git add -A ✔️ ✔️ ✔️ Stage all (new, modified, deleted) files
git add . ✔️ ✔️ Stage new and modified files only in current folder
git add -u ✔️ ✔️ Stage modified and deleted files only

Git 2.x版

Command New Files Modified Files Deleted Files Description
git add -A ✔️ ✔️ ✔️ Stage all (new, modified, deleted) files
git add . ✔️ ✔️ ✔️ Stage all (new, modified, deleted) files in current folder
git add --ignore-removal . ✔️ ✔️ Stage new and modified files only
git add -u ✔️ ✔️ Stage modified and deleted files only

长格式标志:

gitadd-A相当于gitadd--allgitadd-u等同于gitadd--update

进一步阅读:

初学者Git:权威实用指南学习Git的资源学习Git分支用D3解释Git

其他回答

一个更精炼的快速答案:

两者都在下面(与git add--all相同)

git add -A

暂存新的+修改的文件

git add .

阶段已修改+已删除文件

git add -u

git添加。等于git add-A。仅将当前文件夹和子文件夹中的文件添加到索引中。

gitadd-A将工作树中所有文件夹的文件添加到索引中。

注:有关Git 2.0的信息(2014-05-28)。

此答案仅适用于Git 1.x版本。有关Git 2.x版本,请参阅其他答案。


摘要:

gitadd-A阶段所有更改git添加。暂存新文件和修改,而不删除(在当前目录及其子目录上)。gitadd-u阶段修改和删除,无需新文件


详细信息:

git-add-A相当于git-add。;git-add-u。

关于gitadd的要点。它查看工作树,并将所有这些路径添加到已阶段的更改中,如果这些更改已更改或是新的且未被忽略,则不会阶段任何“rm”操作。

gitadd-u查看所有已跟踪的文件,如果这些文件不同或已被删除,则对这些文件进行更改。它不添加任何新文件,只对已跟踪的文件进行更改。

gitadd-A是实现这两个目的的便捷快捷方式。

您可以使用以下方式测试差异(注意,对于Git 2.x版本,您的Git-add.Git状态输出将不同):

git init
echo Change me > change-me
echo Delete me > delete-me
git add change-me delete-me
git commit -m initial

echo OK >> change-me
rm delete-me
echo Add me > add-me

git status
# Changed but not updated:
#   modified:   change-me
#   deleted:    delete-me
# Untracked files:
#   add-me

git add .
git status

# Changes to be committed:
#   new file:   add-me
#   modified:   change-me
# Changed but not updated:
#   deleted:    delete-me

git reset

git add -u
git status

# Changes to be committed:
#   modified:   change-me
#   deleted:    delete-me
# Untracked files:
#   add-me

git reset

git add -A
git status

# Changes to be committed:
#   new file:   add-me
#   modified:   change-me
#   deleted:    delete-me

根据Charles的指示,经过测试后,我提出的理解如下:

# For the next commit
$ git add .   # Add only files created/modified to the index and not those deleted
$ git add -u  # Add only files deleted/modified to the index and not those created
$ git add -A  # Do both operations at once, add to all files to the index

这篇博客文章也可能有助于了解在什么情况下可以应用这些命令:从Git工作目录中删除已删除的文件。

这在2.0中不再适用。添加等于为同一路径添加-A,唯一的区别是树的其他路径中是否有新文件

Git版本1.x

Command New Files Modified Files Deleted Files Description
git add -A ✔️ ✔️ ✔️ Stage all (new, modified, deleted) files
git add . ✔️ ✔️ Stage new and modified files only in current folder
git add -u ✔️ ✔️ Stage modified and deleted files only

Git 2.x版

Command New Files Modified Files Deleted Files Description
git add -A ✔️ ✔️ ✔️ Stage all (new, modified, deleted) files
git add . ✔️ ✔️ ✔️ Stage all (new, modified, deleted) files in current folder
git add --ignore-removal . ✔️ ✔️ Stage new and modified files only
git add -u ✔️ ✔️ Stage modified and deleted files only

长格式标志:

gitadd-A相当于gitadd--allgitadd-u等同于gitadd--update

进一步阅读:

初学者Git:权威实用指南学习Git的资源学习Git分支用D3解释Git