git: git add --ignore-removal git add --all 区别
遇到的問題
在倉庫中刪除文件后,試圖直接用 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
原文:https://blog.csdn.net/JNingWei/article/details/78494478?
總結
以上是生活随笔為你收集整理的git: git add --ignore-removal git add --all 区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NDK JNI方式读写Android系
- 下一篇: git apply、git am打补丁.