如何从我的 Git 存储库中删除未引用的 blob [英] How to remove unreferenced blobs from my Git repository

查看:35
本文介绍了如何从我的 Git 存储库中删除未引用的 blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 GitHub 存储库,它有两个分支 - masterrelease.

I have a GitHub repository that had two branches - master and release.

release 分支包含二进制分发文件,这些文件导致存储库非常大(超过 250 MB),所以我决定清理一下.

The release branch contained binary distribution files that were contributing to a very large repository size (more than 250 MB), so I decided to clean things up.

首先我通过git push origin :release删除了远程发布分支.

First I deleted the remote release branch, via git push origin :release.

然后我删除了本地 release 分支.首先,我尝试了 git branch -d release,但 Git 说错误:分支 'release' 不是您当前 HEAD 的祖先." 这是真的,所以我做了 git branch -D release 来强制删除它.

Then I deleted the local release branch. First I tried git branch -d release, but Git said "error: The branch 'release' is not an ancestor of your current HEAD." which is true, so then I did git branch -D release to force it to be deleted.

但是我的存储库大小,无论是在本地还是在 GitHub 上,仍然很大.然后我浏览了常用的 Git 命令列表,比如 git gc --prune=today --aggressive,但没有任何运气.

But my repository size, both locally and on GitHub, was still huge. So then I ran through the usual list of Git commands, like git gc --prune=today --aggressive, without any luck.

按照 Charles Bailey 在 SO 1029969 我能够获得最大 blob 的 SHA-1 哈希列表.然后我使用 SO 460331 中的脚本找到斑点......还有五个最大的斑点不存在,但发现了较小的斑点,所以我知道脚本正在运行.

By following Charles Bailey's instructions at SO 1029969 I was able to get a list of SHA-1 hashes for the biggest blobs. I then used the script from SO 460331 to find the blobs...and the five biggest don't exist, though smaller blobs are found, so I know the script is working.

我认为这些博客是来自 release 分支的二进制文件,在删除该分支后,它们以某种方式被留下了.摆脱它们的正确方法是什么?

I think these blogs are the binaries from the release branch, and they somehow got left around after the delete of that branch. What's the right way to get rid of them?

推荐答案

我向你展示了这个有用的命令,git-gc-all",保证删除所有你的 Git 垃圾,直到他们可能会出现额外的配置变量:

I present to you this useful command, "git-gc-all", guaranteed to remove all your Git garbage until they might come up extra configuration variables:

git -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 -c gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.pruneExpire=now gc

您可能还需要先运行以下内容:

You might also need to run something like these first:

git remote rm origin
rm -rf .git/refs/original/ .git/refs/remotes/ .git/*_HEAD .git/logs/
git for-each-ref --format="%(refname)" refs/original/ | xargs -n1 --no-run-if-empty git update-ref -d

您可能还需要删除一些标签[1]:

You might also need to remove some tags[1]:

git tag | xargs git tag -d

我把所有这些都放在一个脚本中:git-gc-all-ferocious.

I put all this in a script: git-gc-all-ferocious.

[1].信用:Zitrax'评论

这篇关于如何从我的 Git 存储库中删除未引用的 blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆