总结git的几个问题及解决办法

前言

原来学git的时候只知其一;不知其二的,只会几个基础用法,一遇到问题就蒙了,此次在此总结历史遇到的几个问题及应对方法。git

clone错误

image.png
首先是这周下载github的一个项目,包错如上图所示。错误的大体意思是:须要读取的数据尚未完成,可是传输数据的链接被关闭了。经过网上试了无数种方法得出。
缘由1:缓存区溢出
解决办法:命令行输入github

git config http.postBuffer 524288000

将缓存区设置为500m,
缘由2:网络下载速度缓慢
解决方法:命令行输入缓存

git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999

配置git的最低速与最低速时间。若是依旧clone失败,则首先浅层clone,而后更新远程库到本地网络

git clone --depth=1 http://gitlab.xxx.cn/yyy/zzz.git
git fetch --unshallow

最终我经过这两条命令成功解决。gitlab

从远程git仓库拉取分支

成功克隆项目后,老师让切到102分支,可是我本地没有102分支,怎么作呢。通过又一通网上方法试验后,顺利解决。
1.post

git branch -a

查看本地分支,咱们刚从远程git仓库拉下来的分支固然没有102分支了。
2.fetch

git fetch origin 102

拉去远程git仓库的102分支到本地仓库
3.spa

git checkout -b 102

在本地新建立一个102分支
4.命令行

git pull origin 102

拉取102分支到本地。
或者若是你尚未克隆远程仓库代码,能够直接克隆远程仓库某一分支到本地code

git clone -b 102 https://xxx.git

本地与远程代码不相符

git push origin XXX时报这个错

error: failed to push some refs to 'https://git.XXX.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这是因为你第一次git push origin XXX时,远程仓库已经有了其余更改,你点了同步最新更改,而后再想git push origin XXX时,本地仓库与远程仓库分支代码不一致形成的。
你须要

git pull origin XXX

合并远程分支代码到本地分支。而后再提交。
或者当其余人提交代码后,你能够更新你的代码与远程仓库代码保持一致。

git fetch 
git merge origin/master

总结

在网上看到了一张图,能够帮助理解git命令,在此分享给你们
image.png

版权声明

本文做者:河北工业大学梦云智开发团队 - 赵凯强

相关文章
相关标签/搜索