git add .とgit add -A
いろんな変更をした時に、一度にaddしたいときがある。
(変更毎にステージするとしても、最後の一回とかに使いたい時があります)
そんなときに使うコマンドとして、
git add .
git add -A
が候補に上がりますが、どう違うのでしょうか。どちらでもいいのでしょうか。
git add .はカレントディレクトリだけ
.
が意味するように、今のディレクトリを参照しています。
今のディレクトリをすべてaddするので、今のディレクトリより上の階層のものはaddすることは出来ません。
git add -Aはすべて
allを差すAです。
なので、今のディレクトリより上の階層のものもaddされます
比較
~/D/w/i/a/Console ❯❯❯ (xxx ☡) git status On branch xxx Untracked files: (use "git add <file>..." to include in what will be committed) ../aaa.txt nothing added to commit but untracked files present (use "git add" to track)
自分より上の階層に新しいファイルがあります。
~/D/w/i/a/Console ❯❯❯ (xxx ☡) git add . ~/D/w/i/a/Console ❯❯❯ (xxx ☡) git status On branch xxx Untracked files: (use "git add <file>..." to include in what will be committed) ../aaa.txt nothing added to commit but untracked files present (use "git add" to track
git add .
ではUntracked filesのままでした。
~/D/w/i/a/Console ❯❯❯ (xxx ☡) git add -A ~/D/w/i/a/Console ❯❯❯ (xxx →) git status On branch xxx Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: ../aaa.txt
git add -A
では、Changes to be committedになっています。