Git 删除远程服务器文件同时保留本地文件实例详解

时间:2022-06-01 22:04:23

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

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

?
1
2
3
git rm --cached filename/-r directory
git commit "xxxx"
git push

1.删除服务器文件,本地保留

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

此时github上已经不存在了

2.删除远程useless 文件夹,本地保留

一定要注意,删除文件夹要使用-r 参数

?
1
2
3
git rm --cached -r useless
git commit -m "remove directory from remote repository"
git push

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

原文链接:http://xfenglin.com/a/12011088250.html