75

遇到存储库问题并尝试了几乎所有可能的配置设置,例如。pack.WindowMemory 等

我相信有人已经将一个大文件签入远程存储库,现在每次我尝试拉取或推送它时,GIT 都会尝试打包它并耗尽内存:

Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 6279, done.
Compressing objects: 100% (6147/6147), done.
fatal: Out of memory, malloc failed (tried to allocate 1549040327 bytes)
error: failed to run repack

尝试了git gcgit repack各种选项,但一直返回相同的错误。

几乎放弃了,即将创建一个新的回购,但我想我会先问问:)

4

5 回答 5

113

我在这里找到了一个对我有用的解决方案。

在 .git/config 文件(客户端和/或服务器)中,我添加了以下内容:

[core]
  packedGitLimit = 128m
  packedGitWindowSize = 128m

[pack]
  deltaCacheSize = 128m
  packSizeLimit = 128m
  windowMemory = 128m
于 2012-10-09T21:01:33.260 回答
20

作为参考(您可能已经看过),处理该问题的 msysgit 案例是票证 292

它提出了几种解决方法:

要禁用某些文件的增量压缩,请在.git/info/attributes中添加:

*.zip binary -delta

Gitattributes 手册页

delta对于属性设置为 false的路径,不会尝试对 blob 进行增量压缩。


也许更简单的解决方法是在提交大文件之前以某种方式重置历史记录,然后从那里重做其他提交。

于 2012-04-24T07:10:38.537 回答
15

编辑:由于git-v2.5.0 (Aug/2015)git-for-windows(以前的 MSysGit )
      提供了Pan.student注意到的64 位版本。       在这个答案中,我建议安装 Cygwin 64 位(提供 64 位 Git 版本)。


当达到 4GB 障碍时,我使用MSysGit遇到了类似的Out of memory, malloc failed问题:

> git --version
git version 1.8.3.msysgit.0

> file path/Git/cmd/git
path/Git/cmd/git: PE32 executable for MS Windows (console) Intel 80386 32-bit

> time git clone --bare -v ssh://linuxhost/path/repo.git
Cloning into bare repository 'repo.git'...
remote: Counting objects: 1664490, done.
remote: Compressing objects: 100% (384843/384843), done.
remote: Total 1664490 (delta 1029586), reused 1664490 (delta 1029586)
Receiving objects: 100% (1664490/1664490), 550.96 MiB | 1.55 MiB/s, done.
Resolving deltas: 100% (1029586/1029586), done.
fatal: Out of memory, malloc failed (tried to allocate 4691583 bytes)
fatal: remote did not send all necessary objects

real    13m8.901s
user    0m0.000s
sys     0m0.015s

MSysGit 在达到 4 GB 障碍后崩溃

最后来自Cygwin的 git 64 位修复它:

> git --version
git version 1.7.9

> file /usr/bin/git
/usr/bin/git: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows

> time git clone --bare -v ssh://linuxhost/path/repo.git
Cloning into bare repository 'repo.git'...
remote: Counting objects: 1664490, done.
remote: Compressing objects: 100% (384843/384843), done.
remote: Total 1664490 (delta 1029586), reused 1664490 (delta 1029586)
Receiving objects: 100% (1664490/1664490), 550.96 MiB | 9.19 MiB/s, done.
Resolving deltas: 100% (1029586/1029586), done.

real    13m9.451s
user    3m2.488s
sys     3m53.234s

来自 Cygwin 的 git 64 位成功

仅供参考linuxhost64 位:

repo.git> git config -l
user.email=name@company.com
core.repositoryformatversion=0
core.filemode=true
core.bare=true

repo.git> git --version
git version 1.8.3.4

repo.git> uname -a
Linux linuxhost 2.6.32-279.19.1.el6.x86_64 #1 SMP Sat Nov 24 14:35:28 EST 2012 x86_64 x86_64 x86_64 GNU/Linux

如果我的回答不能解决您的问题,您还可以查看以下页面:

于 2013-08-29T16:15:17.753 回答
0

所选答案中建议的某些选项似乎仅与问题部分相关或根本没有必要。

通过查看https://git-scm.com/docs/git-config,似乎只需设置以下选项就足够了(仅针对此处的项目设置):

git config pack.windowMemory 512m

从手册:

pack.windowMemory

当命令行上没有给出限制时,git-pack-objects[1] 中每个线程为打包窗口内存消耗的最大内存大小。该值可以后缀为“k”、“m”或“g”。当未配置(或明确设置为 0)时,将没有限制。

有了这个,我从来没有超过每个线程指定的 512m ,实际使用的 RAM 大约是大部分时间的一半。当然,这里选择的数量是用户特定的,具体取决于可用的 RAM 和线程数。

于 2021-03-21T15:01:28.140 回答
-1

这对我有用,但我必须通过命令行设置选项:

git --global core\pack [param] value
于 2016-06-16T14:23:36.780 回答