Git clone 大文件时报错:Out of memory

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替换成要拉取的远程分支名就可以了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值