如果文件已经通过git提交了,但是又想删除掉,只删除掉本地的,然后去git push
是无效的,需要把远程的数据删掉才可以,所以就需要使用到git的删除方法。
一、查看git rm帮助信息
可以看下git rm
的帮助信息
git rm -h usage: git rm [<options>] [--] <file>... -n, --dry-run dry run -q, --quiet do not list removed files --cached only remove from the index -f, --force override the up-to-date check -r allow recursive removal --ignore-unmatch exit with a zero status even if nothing matched --pathspec-from-file <file> read pathspec from file --pathspec-file-nul with --pathspec-from-file, pathspec elements are separated with NUL character
二、模拟删除
这里我们先try一下要删除的文件,避免删除错误,如果觉得操作没什么问题,可以直接删除的。
git rm -rn --cached .idea/
三、删除远程文件
如果没有问题,就可以直接删除了。
git rm -r --cached .idea/
四、设置修改信息
git commit -m "delete .idea"
五、PUSH提交
git push