在上传工程到git上时,有时候会把本地的一些eclipse配置文件传到中央服务器上,这时你先删除本地,再同步中央服务器,显然是不合理的。git提供了一个好的解决方法,可以直接删除中央服务器文件,同时不影响本地文件,命令如下
git rm --cached filename/-r directory
git commit "xxxx"
git push
下面作个例子,在github上建一个useless.log文件,同时再建一个useless的文件夹,里面随便扔点东西
先删除文件
git rm --cached useless.log
git commit -m "remove file from remote repository"
git push
此时github上已经不存在了
下面删除远程useless 文件夹
git rm --cached -r useless
**一定要注意,删除文件夹要使用-r 参数**
git commit -m "remove directory from remote repository"
git push
结果如图所示
大功告成!