在Windows上使用Git,“Out of memory - malloc failed”

80

我遇到了一个仓库的问题,尝试了几乎所有可能的配置设置,例如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,但仍返回相同的错误。

几乎要放弃了,正准备创建一个新的仓库,但还是想先问一下周围的人 :)


也许相关。你们解决了吗? - cregox
在我们的情况下,我们通过我的链接解决了一个7GB的repo问题。如果您不能使用GIT,我的建议是尝试Hg或Perforce。 - cregox
我认为这是MsGit的一个bug,而不是Git本身的问题。也不认为这值得完全放弃Git,尤其不是转向Mercurial! - timothyclifford
如果可以的话,你能不能弄一个Ubuntu的U盘来试试呢? - cregox
一个更新,我做了一个新的仓库,并添加了新文件,它有3GB大小,但是在这里没有链接解决我的问题...唯一有效的方法是下面引用的git config --global pack.threads 1。那个方法起作用了。不管怎样...你试过Ubuntu的闪存驱动器吗? - cregox
可能是重复的问题:Git gc使用过多内存,无法完成 - crashmstr
6个回答

116

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

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

[core]
  packedGitLimit = 128m
  packedGitWindowSize = 128m

[pack]
  deltaCacheSize = 128m
  packSizeLimit = 128m
  windowMemory = 128m

2
看起来msysgit在64位机器上运行时没有使用正确的32位默认值。然而,由于客户端是32位的,它应该这样做。以下是我使用的这些值: [core] packedGitLimit = 256m packedGitWindowSize = 32m [pack] deltaCacheSize = 256m packSizeLimit = 1g windowMemory = 256m - fmuecke
1
我曾经遇到过类似的问题,在我的情况下,禁用zip和自定义二进制压缩文件的增量压缩是有效的。在.git/info/attributes中,我添加了“*.zip binary -delta”。 - MartinTeeVarga
128m 看起来有点低。这是每个线程的吗?如果是,那么它就更有意义了,因为如果 32 位 git 在所有线程中分配超过 4096m,当然会崩溃。 - Force Gaia
在Linux上也有帮助,用于git lfs,当平均文件大小约为100 MB时,提交大小为8 GB。 - Vitaly Zdanevich

21

供参考(您可能已经看到了),处理该问题的msysgit案例是292号票

它提供了几种解决方法:

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

*.zip binary -delta

来自 Gitattributes man page:

对于设置了属性delta为false的路径中的 blobs,不会尝试使用Delta 压缩。


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


很不幸,我已经尝试了大部分,但都没有成功。谢谢你的帮助。 - timothyclifford
1
git config --global pack.windowMemory 256m 对我有效 - Kabbalah
要禁用某些文件的增量压缩,在.git/info/attributes中添加“*.zip binary -delta”。 - MartinTeeVarga

15

编辑:  自git-v2.5.0 (2015年8月)以来,Git For Windows (之前称为MSysGit)
      提供了64位版,如Pan.student所指出。
      在这个答案中,我建议安装Cygwin 64位(提供64位Git版本)。


当达到4GB障碍时,我使用MSysGit时也遇到了类似的内存不足,malloc失败问题:

> 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在达到4GB限制后崩溃

最终来自Cygwin的64位git修复了这个问题:

> 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 上成功获取 64 位的 Git

关于 linuxhost 64位系统的信息:

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

еҰӮжһңжҲ‘зҡ„еӣһзӯ”ж— жі•и§ЈеҶіжӮЁзҡ„й—®йўҳпјҢжӮЁиҝҳеҸҜд»ҘжҹҘзңӢд»ҘдёӢйЎөйқўпјҡ


我使用了来自git-scm.com的64位git来解决在大型代码库上检出分支时出现的内存不足错误。 - rluks
1
安装64位版本解决了我在一个包含“大型”“*.lib”文件(每个文件20-100MB +)的代码库中进行rebase时遇到的“内存不足 - malloc失败”错误。 - Robson

1

选定答案提出的某些选项似乎只部分涉及问题或根本不必要。

从查看 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和线程数,因此对每个用户而言都是不同的。


0
在我的情况下,上述的配置更改没有帮助。有帮助的是简单地重新启动服务器(在我的情况下使用sudo shutdown -r now)。看起来服务器上有一些占用大量内存的东西。希望这对其他人也有帮助。

-1

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

git --global core\pack [param] value

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