无法在git上克隆大型代码仓库

13

我遇到了一个错误:-

Cloning into 'large-repository'...
remote: Counting objects: 20248, done.
remote: Compressing objects: 100% (10204/10204), done.
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

2
你是如何尝试克隆它的? - Nikola Andreev
我正在尝试使用git clone命令:- $ git clone https://ramweexcel@bitbucket.org/weexcel1/higher-education-haryana.git - Ram
与此问题重复:如何下载一个大的Git仓库? - Nikola Andreev
谢谢Nikola。我已经执行了相同的步骤。正在进行克隆... - Ram
你之前选择了正确的答案! - VonC
5个回答

16
git config --global http.postBuffer 524288000

git clone repo_url --depth 1

我按照上述步骤进行操作,最终成功克隆了我的代码。


我已经编辑了我的答案,加上了那个缺失的元素,你可以重新选择它。 - VonC
1
关闭压缩并增加 http.postBuffer 大小对我有用,即使我通过 SSH 克隆仓库。你们知道这个吗?即使使用 SSH 克隆,Git 是否也会使用 http.postBuffer 值呢?有点奇怪,但谁知道呢,对我来说它起作用了 :) - tonix

8

看起来像是curl错误,典型的缓慢的互联网连接导致连接过早关闭。

如此所示,请尝试浅克隆(或切换到ssh)

git clone https://ramweexcel@bitbucket.org/weexcel1/higher-education-haryana.g‌​it --depth 1

即使如此,就像我在2011年记录的那样,您可能需要提高http.postBuffer

git config --global http.postBuffer 524288000

但是这个想法仍然存在:从一个提交深度开始可以有所帮助。

从那里开始,你可以逐渐增加深度

git fetch --depth=<number-of-commits>

然后,经过几次迭代:

git fetch --unshallow

是的,我已经看到了并且执行了相同的步骤。让我们看看会发生什么。克隆正在进行中... - Ram
@Ram 的想法是不要下载完整的历史记录,而只下载最后一次提交。然后尝试从那里扩展。 - VonC

6

首先,尝试下载较少的内容,这样当网络失败时,您就不必从零开始:
来自此答案ingyhere 提供。

First, turn off compression:

git config --global core.compression 0

Next, let's do a partial clone to truncate the amount of info coming down:

git clone --depth 1 <repo_URI>

When that works, go into the new directory and retrieve the rest of the clone:

git fetch --unshallow 

or, alternately,

git fetch --depth=2147483647

Now, do a regular pull:

git pull --all

I think there is a glitch with msysgit in the 1.8.x versions that exacerbates these symptoms, so another option is to try with an earlier version of git (<= 1.8.3, I think).

如果这不能帮助你,因为你的网络仍然不稳定或者你的repo仍然太大,尝试换一个网络——最好使用有线网络。
对我来说,这不是一个选择。VonC's Answer 建议执行 git config --global http.postBuffer 524288000。如果你使用https,也许你需要执行 git config --global https.postBuffer 524288000
最终,对我有效的方法是:
放弃并使用另一台机器
如果它在你的笔记本电脑上能够正常工作,只需将该repo拉到你的笔记本电脑上,然后运行。
git bundle create /my/thumb/drive/myrepo.bundle --all  

并在您的其他计算机上使用以下方式进行还原

git clone /my/thumb/drive/myrepo.bundle

0

收到了相同的错误信息。

真正的原因是磁盘已满,被克隆的仓库大约有20GB。

使用depth=1进行克隆,然后逐渐增加深度。过了一会儿我注意到磁盘几乎满了。

在磁盘上释放了一些空间,删除了部分仓库,然后使用完整深度进行了"git clone"。不幸的是,错误信息(远程端意外挂断)是误导性的。


0
在大多数情况下,这是因为网络慢而发生的。 尝试以块克隆。
然后应该做什么? 步骤1:git clone --depth=1
步骤2: git fetch --depth=x (这里x将是一个整数值,表示提交数量,如果网络慢,请不要给出超过200+的增量顺序值)
多次运行上述命令。
最后: git fetch --unshallow unshallow:Git提供了fetch --unshallow命令来解决这个问题,所以在运行r10k之前,我们只需要在存储库中运行git fetch --unshallow。然而,我们的一些(较旧的)GitLab安装不会创建浅克隆。相反,它们使用单个分离的分支进行完整克隆,所以我们需要使用fetch --all代替。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接