git add -A和 git add . git add -u在功能上看似很相近漆腌,但還是存在一點(diǎn)差別
git add . :他會(huì)監(jiān)控工作區(qū)的狀態(tài)樹庙洼,使用它會(huì)把工作時(shí)的所有變化提交到暫存區(qū)蔫磨,包括文件內(nèi)容修改(modified)以及新文件(new)祝拯,但不包括被刪除的文件您没。
git add -u :他僅監(jiān)控已經(jīng)被add的文件(即tracked file)厂僧,他會(huì)將被修改的文件提交到暫存區(qū)扣草。add -u 不會(huì)提交新文件(untracked file)。(git add --update的縮寫)
git add -A :是上面兩個(gè)功能的合集(git add --all的縮寫)
下面是具體操作例子吁系,方便更好的理解(Git version 1.x):
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
總結(jié):
· git add -A 提交所有變化
· git add -u 提交被修改(modified)和被刪除(deleted)文件德召,不包括新文件(new)
· git add . 提交新文件(new)和被修改(modified)文件,不包括被刪除(deleted)文件