[关闭]
@ghimi 2018-08-16T10:05:27.000000Z 字数 359 阅读 1191

Git 删除已经 add 的文件

未分类


使用 git rm命令即可,有两种选择:
* 使用git rm --cached /file/to/remove ,不删除物理文件,仅将该文件从缓存中删除.
* 使用git rm --f /file/to/remove,不仅将该文件从缓存汇总删除,还会降物理文件删除(不会回收到垃圾桶)

git rm --cachegit reset HEAD 的区别在哪里呢?

如果要删除文件,最好使用 git rm /file/to/remove,而不应该直接在工作区 rm /file/to/remove
如果一个文件已经 add 到暂存区,还没有 commit ,此时如果不想要这个文件了,有两种办法:
1. 用版本库内容清空暂存区, git reset HEAD但要谨慎使用
2. 只把特定文件从暂存区删除,git rm --cached /file/to/remove

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注