git add . :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new),但不包括被删除的文件。
git add -u :他仅监控已经被add的文件(即tracked file),他会将被修改的文件提交到暂存区。add -u 不会提交新文件(untracked file)。(git add --update的缩写)
git add -A :是上面两个功能的合集(git add --all的缩写)
下面是具体操作例子,方便更好的理解(Git version 1.x):
git initecho Change me > change-meecho Delete me > delete-megit add change-me delete-megit commit -m initialecho OK >> change-merm delete-meecho Add me > add-megit status# Changed but not updated:# modified: change-me# deleted: delete-me# Untracked files:# add-megit add .git status# Changes to be committed:# new file: add-me# modified: change-me# Changed but not updated:# deleted: delete-megit resetgit add -ugit status# Changes to be committed:# modified: change-me# deleted: delete-me# Untracked files:# add-megit resetgit add -Agit status# Changes to be committed:# new file: add-me# modified: change-me# deleted: delete-me
总结:
· git add -A 提交所有变化
· git add -u 提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
· git add . 提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件