当我运行git add .时,我会收到这条消息。
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.我看到Git2.0的默认行为将将--ignore-removal更改为--all。但我不知道他们有什么区别。我想有一些例子来理解它。
如果我正确理解了描述,如果我使用git-rm,则不需要使用git add --all .从存储库中删除文件。是那么回事吗?
发布于 2014-01-08 06:24:29
是。它很容易测试:
$ 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.txt和foo.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 .导致我的文件删除被分阶段进行。
发布于 2014-01-08 06:24:28
$ 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 deletedhttps://stackoverflow.com/questions/20988169
复制相似问题