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


当前回答

我讨厌git的分段机制,这在其他SCM工具中找不到。所以我总是使用:

\gitadd--all&&\gitcommit--all

(即使使用\git add--all,\git commit也足够了)


用于添加:

--no-ignore-removal  --all     | add, modify, and remove index entries to match the working tree
--ignore-removal     --no-all  | add, modify             index entries to match the working tree

--intent-to-add                | add an entry for the path to the index,  with no content

-A是--all的缩写

gitadd<pathspec>等于:

对于Git 2.35.1版本:Git add--all<pathspec>Git:Git-add的旧版本--无所有<pathspec>

但是gitadd后面跟nothing,不等于gitadd--all,并且不会做任何事情:

gitadd--all(省略<pathspec>):处理整个工作树中的所有文件(旧版本的git用于将更新限制到当前目录及其子目录)。

gitcommit--全部

告诉命令自动暂存已修改和删除的文件,。你没有告诉Git的新文件不会受到影响

其他回答

Git 2.0改变了一切(2014-05-28):

-A现在是默认值旧的行为现在可以使用--ignore删除。命令行上没有路径的子目录中的gitadd-u和gitadd-A对整个树进行操作。

因此,对于Git 2,答案是:

git添加。和git-add-A。在当前目录中添加新的/修改的/删除的文件gitadd—忽略删除。在当前目录中添加新的/修改的文件git add-u。在当前目录中添加修改/删除的文件如果没有圆点,则添加项目中的所有文件,而不考虑当前目录。

此答案仅适用于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

在Git 2.x中:

如果您直接位于工作目录,那么gitadd-A和gitadd。工作没有区别。如果您在工作目录的任何子目录中,gitadd-A将添加整个工作目录中的所有文件,gitadd。将从当前目录中添加文件。

仅此而已。

-A选项添加、修改和删除索引项以匹配工作树。

在Git 2中,-A选项现在是默认选项。

当。根据Git文档,添加了将更新范围限制为当前所在的目录

如果在使用-A选项时未指定<pathspec>,则会更新整个工作树中的所有文件(旧版本的Git用于限制对当前目录及其子目录的更新)。

我要补充的一点是,如果使用--interactive或-p模式,那么gitadd的行为就像使用了update(-u)标志一样,不会添加新文件。

根据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,唯一的区别是树的其他路径中是否有新文件