首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“所有”和“忽略”之间的区别--“删除”

“所有”和“忽略”之间的区别--“删除”
EN

Stack Overflow用户
提问于 2014-01-08 06:10:10
回答 2查看 794关注 0票数 0

当我运行git add .时,我会收到这条消息。

代码语言:javascript
复制
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 .从存储库中删除文件。是那么回事吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-01-08 06:24:29

是。它很容易测试:

代码语言:javascript
复制
$ 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个文件的存储库:barbar.txtfoo.txt。但也许我不是有意加入bar的。让我们把它删除。

代码语言:javascript
复制
$ 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
EN

Stack Overflow用户

发布于 2014-01-08 06:24:28

代码语言:javascript
复制
$ 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,它将从工作树和索引中删除文件,并添加此更改以提交:

代码语言:javascript
复制
$ 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

摘要:

代码语言:javascript
复制
git add --all . stages all(changed, new, deleted)
git add . stages new and modified, without deleted
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20988169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档