我在运行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.
我看到Git 2.0的默认行为会将--ignore-removal
更改为--all
。
但我不确定它们有什么区别。我想有一些例子来理解它。
如果我正确理解了描述,如果我使用git-rm
,我不需要使用git add --all .
从存储库中删除文件。是吗?
答案 0 :(得分: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
,它将从工作树和索引中删除文件,并将此更改添加到commit:
$ 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
答案 1 :(得分: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.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 .
导致我的文件删除被暂停。