git clone pull error Out of memory, malloc failed (tried to allocate 2147483648 bytes) fatal

git clone pull error Out of memory, malloc failed (tried to allocate 2147483648 bytes) fatal
fatal: Out of memory, malloc failed (tried to allocate 2147483648 bytes) fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.#生效git gc --prunenow核心原因git pull拉远程 pack 包时Git 试图一次申请2GB 内存失败了。最可能的原因按优先级你装的是 32 位 Git本地.git/objects/pack有异常或太大仓库历史/大文件太多机器内存不足或 Git 配置导致解包吃内存先按下面做。1. 先检查 Git 是否 64 位在当前目录执行git --version --build-options看输出里有没有cpu: x86_64如果是cpu: i686那就是 32 位 Git。直接卸载安装Git for Windows 64-bit。这是第一优先级。32 位 Git 很容易在 2GB 附近炸。2. 降低 Git 拉取时的内存占用执行git config --global pack.windowMemory 256m git config --global pack.packSizeLimit 512m git config --global pack.threads 1 git config --global core.packedGitWindowSize 64m git config --global core.packedGitLimit 512m然后重新拉git pull3. 不拉 tag减少数据量如果还是失败执行git pull --no-tags或者更稳一点git fetch --no-tags origin git merge origin/当前分支名当前分支名用这个看git branch --show-current例如当前分支是uatgit fetch --no-tags origin git merge origin/uat4. 清理本地 Git 对象先执行git gc --prunenow如果也报内存错误继续执行git fsck --full如果发现.git/objects/pack有损坏最省事的办法不是修直接重新 clone。5. 最快解决重新浅克隆如果你只是要更新代码不需要完整历史直接这样做cd D:\code\c#\ ren test test_bak然后查看原仓库地址cd D:\code\c#\test_bak git remote -v git branch --show-current假设远程地址是git地址分支是uat重新 clonecd D:\code\c#\ git clone --depth1 -b uat git地址 test这会大幅减少下载和解包压力。不要优先改这个很多人会让你执行git config --global http.postBuffer 524288000这不是你的核心问题。你这里是malloc failed不是 HTTP buffer 太小。乱改这个大概率没用。建议你现在直接按这个顺序执行git --version --build-options如果确认是 64 位再执行git config --global pack.windowMemory 256m git config --global pack.packSizeLimit 512m git config --global pack.threads 1 git config --global core.packedGitWindowSize 64m git config --global core.packedGitLimit 512m git pull --no-tags如果还失败别继续耗时间直接重新--depth1克隆。这个问题继续在旧仓库里修机会成本不划算。