git命令 add -a和add .和add -u 的区别

总结:

  • git add -a 所有的更改操作--新建,更改,删除;
  • git add . 只包括 新建 ,修改操作;无删除;
  • git add -u 只包括修改,删除操作,无新建;

示例:

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 All
  • git add .stages new and modified, without deleted
  • git add -ustages modified and deleted, without new

参考:http://stackoverflow.com/questions/572549/difference-of-git-add-a-and-git-add

posted @ 2013-09-16 11:56  cocoajin  阅读(1124)  评论(0编辑  收藏  举报