关于git的使用和一些报错处理

用法:

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

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

git rm --cached filename/-r directory
git commit "xxxx"
git push
1.删除服务器文件,本地保留

git rm --cached useless.log
git commit -m "remove file from remote repository"
git push
此时github上已经不存在了

2.删除远程useless 文件夹,本地保留
一定要注意,删除文件夹要使用-r 参数

git rm --cached -r useless
git commit -m "remove directory from remote repository"
git push

错误:
1. Updates were rejected because the tip of your current branch is behind

有如下几种解决方法:

1.使用强制push的方法:

$ git push -u origin master -f

这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。

2.push前先将远程repository修改pull下来

$ git pull origin master

$ git push -u origin master

3.若不想merge远程和本地修改,可以先创建新的分支:

$ git branch [name]

然后push

$ git push -u origin [name]

猜你喜欢

转载自www.cnblogs.com/lcglcglcglcglcg/p/11087387.html