Git 如何删除远程服务器文件同时保留本地文件

在上传工程到git上时,有时候会把本地的一些eclipse配置文件传到中央服务器上,这时你先删除本地,再同步中央服务器,显然是不合理的。git提供了一个好的解决方法,能够直接删除中央服务器文件,同时不影响本地文件,命令以下git

git rm --cached filename/-r directory
git commit "xxxx"
git push

下面做个例子,在github上建一个useless.log文件,同时再建一个useless的文件夹,里面随便扔点东西 输入图片说明github

先删除文件服务器

git rm --cached useless.log
git commit -m "remove file from remote repository"
git push

此时github上已经不存在了 输入图片说明less

下面删除远程useless 文件夹eclipse

git rm --cached -r useless
**必定要注意,删除文件夹要使用-r 参数**
git commit -m "remove directory from remote repository"
git push

结果如图所示code

输入图片说明

大功告成!图片

相关文章
相关标签/搜索