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肯定会进行此更改。

在Git2.0中,gitadd-A是默认值:gitadd。等于git add-A。。

gitadd<path>现在与“gitadd-A<path>”相同,因此“git-add-dir/”将注意到您从目录中删除的路径记录移除情况。在旧版本的Git中,“gitadd<path>”忽略了删除。您可以对如果确实需要,请在<path>中只添加添加或修改的路径。

gitadd-A类似于gitadd:/(从顶部git repo文件夹添加所有内容)。注意,git2.7(2015年11月)将允许您添加名为“:”的文件夹!参见Junio C Hamano(gitster)的承诺29abb33(2015年10月25日)。


注意,在谈论gitadd时,从git2.0开始(2014年第一季度或第二季度)。(工作树中的当前路径),必须使用“.”在其他gitadd命令中也是如此。

这意味着:

“git-add-A.”等同于“git-add.;git-add-u”

(注意git-add-A和git-add-u的额外“.”)

因为git add-A或git add-u将在整个工作树上运行(仅启动git 2.0),而不仅仅是在当前路径上运行。

这些命令将在Git2.0中的整个树上运行,以与“gitcommit-a”和其他命令保持一致。由于没有机制使“git-add-u”的行为类似于“git-add-u”,所以对于那些习惯于“git add-u”(没有路径规范)只更新当前子目录中路径的索引的人来说,在git 2.0到来之前开始训练他们的手指明确说出“git add-u”是很重要的。当这些命令在没有路径规范的情况下运行时,以及当您在当前目录之外进行本地更改时,会发出警告,因为Git2.0中的行为会有所不同从今天的版本来看,在这种情况下。

我讨厌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添加。等于git add-A。仅将当前文件夹和子文件夹中的文件添加到索引中。

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

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

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