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 add。gitadd-A将在更新版本的git中暂存所有新的、修改的和删除的文件。

不同之处在于,git add-A将文件存放在属于您工作的git存储库的“更高、当前和子目录”中。但做一个git加法。仅暂存当前目录及其后的子目录中的文件(而不是位于外部的文件,即更高的目录)。

下面是一个示例:

/my-repo
  .git/
  subfolder/
    nested-file.txt
  rootfile.txt

如果您当前的工作目录是/my repo,并且您执行rm rootfile.txt,然后是cd子文件夹,然后是git add。,则它将不暂存已删除的文件。但是,无论您从何处执行命令,执行git add-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

根据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的分段机制,这在其他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 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