Git在clone远程大文件时,报错Out of memory。意思是说clone的文件太大了,超出了限制,具体错误如下:
remote: Counting objects: 13847, done.
remote: error: Out of memory, malloc failed (tried to allocate 168827801 bytes)
remote: error: failed to read object e0f64433172d27df0609902b36accefc08b2e932 at offset 50780215 from ./objects/pack/pack-b65cc75a8685ba3c75207208eca4df10186ccd36.pack
remote: fatal: packed object e0f64433172d27df0609902b36accefc08b2e932 (stored in ./objects/pack/pack-b65cc75a8685ba3c75207208eca4df10186ccd36.pack) is corrupt
remote: aborting due to possible repository corruption on the remote side.
fatal: protocol error: bad pack header
解决方案:
git config --global core.compression 0
git clone --depth 1 项目地址
以上就可以正常clone远程项目到本地了。但是这里还有一个问题:depth 用于指定clone的深度,当为1时表示只clone最近一次commit。项目小了就可以解决前面说的文件过大导致的Out of memory。但这只会把默认的分支clone下来,其它分支无法显示。所以当使用git pul --all的时候无法获取到远程分支,使用git branch -r 也无法看到远程分支。
解决方案:
方案1:
找到项目的 .git/config
将原文件:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/ReactiveX/rxjs
fetch = +refs/heads/master:refs/remotes/origin/master
[branch "master"]
remote = origin
merge = refs/heads/master
修改成:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/ReactiveX/rxjs
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
方案2:
拉取其它分支的时候使用如下命令:
git clone --depth 1 远程项目地址
git remote set-branches origin 'remote_branch_name'
git fetch --depth 1 origin remote_branch_name
git checkout remote_branch_name
将remote_branch_name替换成要拉取的远程分支名就可以了。