"git add -A" 和 "git add ." 的区别是什么?

3431
12个回答

5
-A选项会添加、修改和删除索引条目以匹配工作树。
在Git 2中,-A选项现在是默认的。
当添加一个.时,更新的范围限制在当前目录下,根据Git documentation
如果使用-A选项时没有指定,则会更新整个工作树中的所有文件(旧版本的Git将更新限制为当前目录及其子目录)。
需要补充的一点是,如果使用--interactive或-p模式,则git add将表现得好像使用了更新(-u)标志而不是添加新文件。

-1

我讨厌git的暂存机制,其他版本控制工具中也找不到这种机制。

所以我总是使用:

\git add --all && \git commit --all

(即使只用\git add --all\git commit已经足够了)


对于add

--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 的缩写

git add <pathspec> 等同于:

对于 Git 的版本 2.35.1:git add --all <pathspec>
旧版本的 Git: git add --no-all <pathspec>

但是,git add 后面什么也不跟时,并不等同于 git add --all,而是什么也不做:

enter image description here

git add --all(省略<pathspec>):处理整个工作树中的所有文件(旧版本的Git仅限于当前目录及其子目录)。

git commit --all

告诉命令自动暂存已修改和删除的文件,未告知Git的新文件不受影响。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接