Difference between “git add -A” and “git add .” and "git add -u"

来源:互联网 发布:mac word转pdf 白边 编辑:程序博客网 时间:2024/06/05 05:19

"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 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

Summary:

  • git add -A stages All
  • git add . stages new and modified, without deleted

  • git add -u stages modified and deleted, without new

原文来自:http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add

0 0
原创粉丝点击