致命:内存不足,malloc在Ubuntu VM上的git pull上失败了

时间:2017-03-06 15:42:39

标签: linux git ubuntu

我在我的Ubuntu VM上运行了 git pull ,我得到了

Enter passphrase for key '/root/.ssh/id_rsa': 
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 7 (delta 4), reused 0 (delta 0)
Unpacking objects: 100% (7/7), done.
From bitbucket.org:bheng/app
   7406b4e..8f5e3dc  master     -> origin/master
Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 5384, done.
fatal: Out of memory, malloc failed (tried to allocate 306851376 bytes)
error: failed to run repack
Updating 7406b4e..8f5e3dc
Fast-forward
Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 5384, done.
fatal: Out of memory, malloc failed (tried to allocate 306851376 bytes)
error: failed to run repack
 resources/views/layouts/fe/meta.blade.php | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

正如你最后所看到的那样 - 它可以很好地完成当地的变化。

但我只是想摆脱那些错误......我该如何摆脱它们?清除我的缓存?

我看到git gc是推荐的清理本地文件的命令,但我甚至无法运行它。

Counting objects: 7709, done.
fatal: Out of memory, malloc failed (tried to allocate 306851376 bytes)
error: failed to run repack

我也试过

git fsck

Checking object directories: 100% (256/256), done.
Checking objects: 100% (2377/2377), done.
dangling commit 32c8482dcc118bd64c1f8e45ee093c286a840e5d
dangling commit abce13f3bfb8c3833c7b76f4aea9cd28caa3af03
dangling blob c9131033c721c0b90c86bf7b32377588354363ec
dangling commit de6d83d883d35f97cb211233e2283c9d79e6f922
dangling blob d535c98d611cca74af45633c77680bb2bdc5e55a

最后,再次运行git pull

Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 5384, done.
fatal: Out of memory, malloc failed (tried to allocate 306851376 bytes)
error: failed to run repack
Already up-to-date.

非常感谢任何提示/建议!!

3 个答案:

答案 0 :(得分:3)

好吧,你的系统只是RAM不足。如果需要,Git会定期运行git gc,这是错误消息的来源,因为您也可以手动运行它。它试图重新打包你的Git存储库,并在尝试分配293 MiB额外的RAM时失败。将更多RAM放入您的盒子或至少扩大交换大小,即使只是暂时使重新包装成功完成。如果您只是想暂时帮助重新打包完成,则可以在系统运行时轻松添加一些交换文件。如果只是暂时的话,可以在https://help.ubuntu.com/community/SwapFaq#Four-step_Process_to_Add_Swap_File找到文档,而无需执行最后一步。

答案 1 :(得分:0)

请尝试按照此处的说明操作:https://stackoverflow.com/a/8761464/1278288

git config --global pack.windowMemory "100m" git config --global pack.packSizeLimit "100m" git config --global pack.threads "1"

它应该减少所需的内存。

尽管至少有1GB的掉期是个好主意。

答案 2 :(得分:0)

您的RAM大小可能会更小,您必须添加交换空间。 我在ubuntu 16.04中做到了,并解决了这个问题

如果交换,将显示以下代码

free -h

如果swap为零,则检查是否有足够的内存来添加swap

df -h

我的RAM是1 GB,所以还要分配1GB来交换空间

sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show

这将显示类似的内容,然后显示成功

NAME      TYPE  SIZE USED PRIO
/swapfile file 1024M   0B   -1

谢谢