How can I recover from “fatal: Out of memory? mmap failed: Cannot allocate memory” in Git?

前端 未结 2 1094
情话喂你
情话喂你 2020-12-15 09:52

Let me start with some context:

I had to upgrade a crucial Magento webshop to a new version. To be sure all existing code would still work after the upgrade and make

相关标签:
2条回答
  • 2020-12-15 10:27

    I've seen a few reports of this happening when you do "git init --bare" in a non-empty directory.

    Are you by any chance working in/with a "bare"/"server" repository that isn't empty (that is, has anything else besides the .git directory in it)?

    0 讨论(0)
  • 2020-12-15 10:33

    The error you're getting comes from the large files in your repository. Git is trying to put the entire contents of the file in memory, which makes it croak.

    Try Upgrading Git

    Git 1.7.6 was released last month and has this lovely bit in its release notes:

    Adding a file larger than core.bigfilethreshold (defaults to 1/2 Gig) using "git add" will send the contents straight to a packfile without having to hold it and its compressed representation both at the same time in memory.

    Upgrading to 1.7.6 might enable you to run git gc and maybe even git merge, but I can't verify because it's hard get a repository into that state (the conditions must be just right).

    Try Removing the Offending Files

    If upgrading Git doesn't help, you can try removing the large files from the repository using git filter-branch. Before you do that, try backing up the large files using git cat-file -p <commit_sha1>:path/to/large/file >/path/to/backup/of/large/file.

    You'll want to do these operations on your most beefy machine (lots of memory).

    If this works, try re-cloning to the other machines (or simply rsync the .git directory).

    0 讨论(0)
提交回复
热议问题