git

git clone超大项目出现EOF异常解决方案

Posted by JamesPxy on 2021-06-16

最近遇到10多个G的大项目需要clone代码,直接根本拉不下来,会出现EOF异常,第一次为了拉项目代码犯愁,这里总结一下clone大项目解决方案。

遇到异常如下:

1
2
3
4
5
6
remote: Compressing objects:   0% (3902/531163)   
remote: Compressing objects: 100% (531163/531163), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: index-pack failed

解决方案如下:

1. 修改git基本配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14

// 1. compression 是压缩的意思,从 clone 的终端输出就知道,服务器会压缩目标文件,然后传输到客户端,客户端再解压。
// 取值为 [-1, 9],-1 以 zlib 为默认压缩库,0 表示不进行压缩,1…9
// 是压缩速度与最终获得文件大小的不同程度的权衡,数字越大,压缩越慢,当然得到的文件会越小。

$ git config --local core.compression -1

// 2. 增加git的缓存大小 将http.postBuffer设置的尽量大

$ git config --local http.postBuffer 1048576000 (1G)

// 3. 设置低速等待时长 单位 秒

$ git config --local http.lowSpeedTime 999999

2. 分段拉代码

1
2
3
4
5
$ git clone --depth=1
# 说明:可以看到我们只克隆下包含最近一次commit的一个分支,这样这个项目文件就不会很大

# 而如果我们想只克隆某个指定分支的最近一次commit,可以使用下面命令
$ git clone --depth 1 --branch english URL

总结:用 git clone --depth=1 的好处是限制 clone 的深度,不会下载 Git 协作的历史记录,这样可以大大加快克隆的速度
depth用于指定克隆深度,为1即表示只克隆最近一次commit
适合用 git clone --depth=1 的场景:你只是想clone最新版本来使用或学习,而不是参与整个项目的开发工作

如果我们想把其他远程分支(如master)也克隆到本地,我们需要用下面的命令

1
2
3
$ git remote set-branches origin 'remote_branch_name'
$ git fetch --depth 1 origin remote_branch_name
$ git checkout remote_branch_name

转换存储库为完整存储库,此命令用于将浅层转换为完整的存储库,消除浅层存储库所施加的所有限制。

1
2
3
git pull --unshallow
#或者
git fetch --unshallow

其它常用命令:

1
2
3
4
5
6
$ git clone --depth 1 https://github.com/dogescript/xxxxxxx.git
$ git remote set-branches origin 'remote_branch_name'
$ git fetch --depth 1 origin release
$ git checkout remote_branch_name

$git pull --rebase origin release

mac升级到Big Sur之后出现git不可用问题解决方案

1
2
3
4
5
1. 下载缺失命令行工具
$ xcode-select --install

2. 根据提示切换环境
$ sudo xcode-select --switch /Library/Developer/CommandLineTools/

参考链接:

https://blog.csdn.net/weixin_45787652/article/details/107628513



支付宝打赏 微信打赏

赞赏一下