Git仓库过大致使clone失败的解决方法

在这里插入图片描述
在这里插入图片描述

remote: Enumerating objects: 2308, done.
remote: Counting objects: 100% (1351/1351), done.
remote: Compressing objects: 100% (850/850), done.
error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly: CANCEL (err 8)
error: 7667 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

原因分析

一般这种情况都是因为项目分支过多,导致你要下载的东西太多,从而引起这个问题。网上有一个流传比较多的修改方案:

git config --global core.compression -1

使用上述命令,来修改压缩模式,尝试过了没有用。

解决思路

引起这个问题的根源是文件过多,所以我们可以分批次下载文件,先下载一部分,再下载剩下的。以下是解决方案:

关闭 core.compression

git config --global core.compression 0

获取最近一次提交

使用depth这个指令来下载最近一次提交

git clone --depth 1  [仓库链接] 

在这里插入图片描述

获取完整库

git fetch --unshallow 

期间有可能失败,重试一下,如果还不行,试试延长克隆时间
在这里插入图片描述
成功后,整个仓库就都下载下来了,包括历史的提交

延长克隆的时间

git config --global http.postBuffer 600000

pull一下查看状态,问题解决

git pull --all

在这里插入图片描述
可以看到代码库已经完成clone。

经过分支名称去拉取分支信息以及checkout

git branch -a
git remote set-branches origin '远程分支名称'
git fetch --depth 1 origin 远程分支名称
git checkout 远程分支名称

利用镜像网站

将链接中的 github.com 替换为 github.com.cnpmjs.org 或其他镜像地址
如果报以下错误

Could not resolve host: github.com.cnpmjs.org

在git控制台上输入下面这句,然后在正常去拉取,它会使你默认使用镜像

git config --global url."https://github.com.cnpmjs.org/".insteadOf https://github.com/

如果需要替换回原来的默认地址

git config --global url."https://github.com/".insteadOf https://github.com.cnpmjs.org/

参考资料

git仓库过大致使clone失败的解决方法
github国内镜像https://hub.fastgit.xyz/使用指南
git提交或克隆报错fatal: unable to access ‘https://github.com/tata20191003/autowrite.git/‘: Failed to connect

猜你喜欢

转载自blog.csdn.net/qq_32808455/article/details/135616105