如何分块推送 Git 镜像?

5
我目前正在将一个大型Git项目转移到Git-LFS,这包括重写整个仓库历史记录以创建并包含某些文件在Git-LFS中。这部分过程很顺利。
然而,我在将新仓库推送到上游远程(GitHub)时遇到了问题,因为它似乎太大了,无法一次性推送:
PS > git push
Counting objects: 337130, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (73730/73730), done.
remote: fatal: pack exceeds maximum allowed size
fatal: sha1 file '<stdout>' write error: Broken pipe30 MiB/s
error: failed to push some refs to 'git@github.com:my-repo.git'

我尝试使用HTTPS,但结果类似:

PS > git push
Counting objects: 337130, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (73730/73730), done.
error: RPC failed; curl 55 SSL_write() returned SYSCALL, errno = 10053
fatal: The remote end hung up unexpectedly
Writing objects: 100% (337130/337130), 3.58 GiB | 388.62 MiB/s, done.
Total 337130 (delta 261838), reused 337130 (delta 261838)
fatal: The remote end hung up unexpectedly
Everything up-to-date

这似乎是比较常见的问题,有一些解决方案可供选择,包括指定每次上传提交的块。然而,我的仓库是一个镜像克隆,不支持指定refspecs:
PS > git push -u origin HEAD~5000:refs/heads/master
error: --mirror can't be combined with refspecs

你有什么想法可以将镜像存储库分块推送到远程上游?

1个回答

2

通过将 remote.name.mirror 在 git 配置中设置为 false,可以暂时禁用推送镜像。

使用 --mirror 推送会简单地推送所有引用(refs/ 下的所有内容),并且将存储库配置为推送镜像有效地设置了 --mirror 标志。如果要推送有限的提交集,则需要执行 git push remote refspec 操作,以便您的 refspec 可以引用足够小的一组提交。

在这里,您可能不需要使用 -u,因为这会为当前分支设置上游,但是推送镜像通常根本不使用上游。

(一旦在远程具有足够多的提交,您就可以重新启用推送镜像,因为从那时起,您发送上去的“瘦包”应该更小:实际上是瘦的,而不仅仅是理论上瘦的 :-) .)


你能展示给我如何暂时禁用推送镜像吗? - S.Richmond
1
在git配置中将remote.<name>.mirror设置为false。请参阅https://www.kernel.org/pub/software/scm/git/docs/git-config.html。 - torek
好的。我也在refspecs方面遇到了一些问题。我们有大约15k个提交记录。你认为将其分成3或4次推送的简单方法是什么? - S.Richmond
很难知道在哪里划分事物。您可以使用 git rev-list --count 查看从某个起始点可达的提交数量,以及一些截止点,例如 git rev-list --count 8765432 ^2222223 将告诉您在这两个点之间有多少次提交(这里的 222... 是已经推送的提交,而 876... 是拟议的下一批提交)。但这只是提交的数量,而不是对象的数量,更不用说大小了。[续] - torek
可能有一些方法可以使用 git pack-objects --thin 来构建一个“测试”包并检查其大小,从而自动锁定某个限制,但我不知道如何立即做到这一点。 - torek
显示剩余4条评论

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