git clone 报错:error: RPC failed; curl 18 transfer closed with outstanding read data remain

报错信息

error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

git 有两种拉代码的方式,一个是 HTTP,另一个是 ssh。git 的 HTTP 底层是通过 curl 的。HTTP 底层基于 TCP,而 TCP 协议的实现是有缓冲区的。所以这个报错大致意思就是说,连接已经关闭,但是此时有未处理完的数据。究其原因是因为curl的postBuffer的默认值太小,我们需要调整它的大小,加大缓存区,终端重新配置大小。
git 在clone 项目时可能因为git 项目太大,提交历史很长,导致clone的时候花大半天都clone不下来的问题。而且如果直接git clone,必须一次把所有的历史clone下来,否则失败就直接丢弃所有。如果只是需要最新内容,或者网络不好,总是网络中断的情况,非常不友好。
实际上,如果只需要看最新的提交,使用depth参数,就可以实现只clone最新的代码

解决办法:

一,加大缓存区

git config --global http.postBuffer 524288000

这个大约是500M,可以根据你需要下载的文件大小,将postBuffer值配置成合适的大小。

可以根据以下命令查看postBuffer。

git config --list

二、clone最新的提交,–depth 1

git clone https://github.com/flutter/flutter.git --depth 1

–depth 1的含义是复制深度为1,就可以实现只clone最新的代码,就是每个文件只取最近一次提交,不是整个历史版本。

三、换协议

clone http方式换成SSH的方式,即 https:// 改为 git://
例如git clone https://github.com/flutter/flutter.git
换成git clone git://github.com/flutter/flutter.git

参考文档

链接: https://blog.csdn.net/shareye1992/article/details/81626554.
链接: https://blog.csdn.net/dzhongjie/article/details/81152983.
链接: https://blog.csdn.net/weixin_41872403/article/details/86769287.

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐