在git代码过程,有大文件,导致报错
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
error: 7965 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 http.postBuffer 524288000
//或全局设置
git config --global http.postBuffer 2M
Mac电脑可在根目录下的.gitconfig文件查看是否生效,如下图是已经生效
- 进行浅克隆
加大缓存后重新克隆,还是失败,可以再尝试使用--depth进行浅克隆
// 克隆当前分支最后10次的提交,尽量少一点,保证文件比较小
git clone --depth 10 https://github.com/xxxxxxx.git
// 先cd到代码路径下,然后切换到自己需要的远程分支
git remote set-branches origin '分支名'
git fetch --depth 10 origin 分支名
git checkout 分支名
使用下面的命令拉取剩余所有分支提交记录
// 拉取所有提交记录
git fetch --unshallow
// 如果项目历史悠久,也可选取只拉取部分提交记录,很久之前的提交对我们来讲一般意义不大
git fetch --depth=100
如果有强迫症,可以先拉取一部分再--unshallow
接着查看下本地所有分支
git branch -a
如果本地分支不完整,继续使用git fetch --unshallow拉取,会报以下错误
fatal: --unshallow on a complete repository does not make sense
这是因为git并不认为当前本地的目录是shallow, 而是complete,可以继续执行以下操作解决
// 执行
git config remote.origin.fetch
// 输出
+refs/heads/develop:refs/remotes/origin/develop
// 执行以下命令,修改配置
sudo git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
// 再次查看
git config remote.origin.fetch
// 输出,表示配置修改成功
+refs/heads/*:refs/remotes/origin/*
// 接下来更新所有分支
git remote update
// 最后再查看下本地的所有分支
git branch -a