前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >git: git add --ignore-removal & git add --all 区别

git: git add --ignore-removal & git add --all 区别

作者头像
JNingWei
发布2018-09-28 11:33:27
2.5K0
发布2018-09-28 11:33:27
举报
文章被收录于专栏:JNing的专栏JNing的专栏

遇到的问题

在仓库中删除文件后,试图直接用 git add . 将所有删除工作提交暂存区,结果遇到了报错:

$ 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 '.idea/Wood_Tool.iml' 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 add --all 解决了问题。

进一步探究

指令

区别

git add --ignore-removal <pathspec>

不会 将删除操作提交至暂存区

git add --all <pathspec>

将删除操作提交至暂存区

很明显我们需要的是第二种。

实验代码

# 新建仓库并添加文件
$ git init
Initialized empty Git repository in /media/hok/test/.git/
$ git add .
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   1.txt
    new file:   2.txt
    new file:   3.txt

# 删除文件后尝试用 git add --all
$ rm 1.txt 
$ git add --all
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   2.txt
    new file:   3.txt

# 删除文件后尝试用 git add . --ignore-removal,则删除操作 依然未被 提交至暂存区
$ rm 2.txt 
$ git add . --ignore-removal
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   2.txt
    new file:   3.txt

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:    2.txt

$ 


本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年11月09日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 遇到的问题
  • 进一步探究
  • 实验代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档