2014-01-08 55 views
0

我運行git add .時收到此消息。`--all`和`--ignore-removal`之間的區別

warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal', 
whose behaviour will change in Git 2.0 with respect to paths you removed. 
Paths like 'config/.deploy.rb.swp' that are 
removed from your working tree are ignored with this version of Git. 

* 'git add --ignore-removal <pathspec>', which is the current default, 
    ignores paths you removed from your working tree. 

* 'git add --all <pathspec>' will let you also record the removals. 

Run 'git status' to check the paths you removed from your working tree. 

我看到的Git 2.0的默認行爲將改變--ignore-removal--all。 但我不確定它們有什麼不同。我想有一些例子來理解它。

如果我正確理解說明,如果我使用git add --all .,我不需要使用git-rm從存儲庫中刪除文件。是對的嗎?

回答

0

是。這很容易測試:

$ git init . 
Initialized empty Git repository in /private/tmp/git/.git/ 

$ touch foo.txt 

$ touch bar 

$ touch bar.txt 

$ git add . 

$ git commit 
[master (root-commit) dae701b] Add files. 
3 files changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 bar 
create mode 100644 bar.txt 
create mode 100644 foo.txt 

好的。我有一個3個文件的存儲庫:bar,bar.txtfoo.txt。但是,也許我不是故意添加bar。讓我們刪除它。

$ rm bar 

$ git add --all . 

$ git commit 
[master 070fb0e] Deleted mistakenly added file. 
1 file changed, 0 insertions(+), 0 deletions(-) 
delete mode 100644 bar 

正如你所看到的,git add --all .導致我的文件刪除得到階段。

0
$ ls 
a 
$ touch b 
$ ls 
a b 
$ git status 
On branch master 
Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

     b 

nothing added to commit but untracked files present (use "git add" to track) 
$ rm a  
$ git status 
On branch master 
Changes not staged for commit: 
    (use "git add/rm <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

     deleted: a 

Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

     b 

no changes added to commit (use "git add" and/or "git commit -a") 
$ git add . --ignore-removal 
$ git status 
On branch master 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

     new file: b 

Changes not staged for commit: 
    (use "git add/rm <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

     deleted: a 

$ git add . --all 
$ git status 
On branch master 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

     deleted: a 
     new file: b 

但是如果你使用git rm filename,它將從工作樹,並從指數中刪除文件,並添加這種變化承諾:

$ ls 
a 
$ git rm a 
rm 'a' 
$ git status 
On branch master 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

     deleted: a 

摘要:

git add --all . stages all(changed, new, deleted) 
git add . stages new and modified, without deleted