11

我在https://bitbucket.org/上有一个仓库

几天前错误地将大量图像文件推送到存储库中。然后文件通过另一个推送被删除。在那之后回购工作正常,但是今天当我尝试从回购中提取时:

$ git pull
Password for 'https://repo@bitbucket.org': 
warning: no common commits
remote: Counting objects: 4635, done.
remote: Compressing objects: 100% (1710/1710), done.
fatal: Out of memory, malloc failed (tried to allocate 4266852665 bytes)
fatal: index-pack failed  

我试过:
1)git config --global pack.windowMemory 1024m
2)

$ git count-objects -v
count: 9
size: 48
in-pack: 4504
packs: 1
size-pack: 106822
prune-packable: 0
garbage: 0

没有运气,不知道下一步我应该采取什么行动......
回购的大小应该是大约10-20m的代码。我接下来应该采取什么行动?

更新 1
我执行了这些命令:

$ git filter-branch --index-filter 'git rm --cached --ignore-unmatch public/images/*' HEAD
Rewrite a1c9fb8324a2d261aa745fc176ce2846d7a2bfd7 (288/288)
WARNING: Ref 'refs/heads/master' is unchanged

$ git push --force --all
Counting objects: 4513, done.
Compressing objects: 100% (1614/1614), done.
Writing objects: 100% (4513/4513), 104.20 MiB | 451 KiB/s, done.
Total 4513 (delta 2678), reused 4500 (delta 2671)
remote: bb/acl: ayermolenko is allowed. accepted payload.
To https://repo@bitbucket.org/repo.git
 + 203e824...ed003ce demo -> demo (forced update)
 + d59fd1b...a1c9fb8 master -> master (forced update)

拉然后工作正常:

$ git pull
Already up-to-date.

但是当我尝试克隆回购时,我得到了

~/www/clone$ git clone git@bitbucket.org:repo.git
Cloning into 'clone'...
remote: Counting objects: 5319, done.
remote: Compressing objects: 100% (1971/1971), done.
fatal: Out of memory, malloc failed (tried to allocate 4266852665 bytes)
fatal: index-pack failed

更新 2
遗憾的是,我没有找到所有的大文件。有些还剩下。所以我要求支持杀死回购的所有日志

更新 3
最后我不得不杀死旧的并创建新的回购。

4

4 回答 4

10

在我的情况下,这就像试图在没有交换的 1GB RAM 盒子中提取一个大仓库一样简单。

我按照本教程https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04在服务器上创建了一些交换空间并开始工作。

他们“更快”的方式:

sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

您可以通过添加到 /etc/fstab 使这些更改永久化:

/swapfile   none    swap    sw    0   0

他们建议添加到 /etc/sysctl.conf:

vm.swappiness=10
vm.vfs_cache_pressure = 50
于 2016-05-17T18:45:53.653 回答
4

如果您是唯一使用此 repo 的人,您可以按照“如何从 Git 中的提交历史记录中清除大文件? ”中描述的 git filter-branch 选项进行操作。

更简单的选择是将 repo 克隆到旧提交,然后强制推送它,如“git-filter-branch删除大文件”中所述。

任何一个都会迫使任何合作者将他/她自己的本地存储库重置为您正在发布的新状态。同样,如果您是唯一的合作者,这不是问题。

于 2012-12-26T10:19:10.020 回答
2

即使大图像文件在被推送后被删除,它们也会保留在git历史记录中。

我建议从 git 历史记录中强行删除它们(我认为这是可能的,但它涉及一个我不知道的微妙过程)。

或者,在错误添加的文件之前拉取存储库,修补存储库以制作相关的小补丁,克隆它,然后使用它(可能带有转储/恢复)作为您的主 git。

我不太清楚细节,但我确实读过它是可能的

于 2012-12-26T08:50:49.787 回答
0

我最近在我的一个存储库中遇到了这个问题。类似的错误,暗示某个地方的仓库中隐藏了一个大文件。

Cloning into 'test_framework'...
remote: Counting objects: 11889, done.
remote: Compressing objects: 100% (5991/5991), done.
Receiving objects:  66% (7847/11889), 3.22 MiB | 43 KiB/sremote: fatal: Out of memory, malloc failed     (tried to allocate 893191377 bytes)
remote: aborting due to possible repository corruption on the remote side.
fatal: early EOFs:  66% (7933/11889), 3.24 MiB
fatal: index-pack failed

为了解决这个问题,我临时创建了一个大型交换驱动器(超过服务器要求的 893191377 字节),遵循方法 2 从这里开始:http ://www.thegeekstuff.com/2010/08/how-to-add-交换空间/

这使我能够成功克隆然后删除罪魁祸首(有人签入了 sql 转储文件)。您可以使用:

git filter-branch --tree-filter 'rm -rf dumpfile.sql' HEAD

从 git repo 中删除文件。

于 2014-07-16T18:48:42.830 回答