"git
add -A" is equivalent to "git
add .; git add -u".
The important point about "git
add ." is that it looks at the working tree and adds all those paths to the staged changes if they are either changed or are new and not ignored, it does not stage any 'rm' actions.
"git
add -u" looks at all the currently tracked files and stages the changes to those files if they are different or if they have been removed. It does not add any new files, it only stages changes to already tracked files.
"git
add -A" is a handy shortcut for doing both.
You can test the differences out with something like this:
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
Summary:
git add -Astages Allgit add .stages new and modified, without deleted
git add -ustages modified and deleted, without new
本文详细解释了Git中add-A、add.与add-u命令的区别:add.会将工作目录中所有已跟踪文件的变化及新增文件加入暂存区,但不包括删除操作;add-u则针对已跟踪文件的变化和删除进行暂存,不处理新增文件;add-A则是两者的结合。

1万+

被折叠的 条评论
为什么被折叠?



