如何从我的git回购中删除未引用的blob [英] How to remove unreferenced blobs from my git repo

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

问题描述

我有一个GitHub仓库,它有两个分支 - master& 发布分支包含二进制分发文件,这些文件有助于实现非常大的回购大小(> 250MB),所以我决定清理干净。



首先我通过 git push origin:release



删除远程发布分支然后我删除了本地发布分支。首先,我尝试了 git branch -d release ,但是git声明了错误:分支'release'不是你当前HEAD的祖先。这是真的,所以我做了 git branch -D release 来强制它被删除。



但是我的本地和GitHub上的存储库大小仍然很大。然后我运行了通常的git命令列表,比如 git gc --prune = today --aggressive ,但没有运气。

按照Charles Bailey的指示在 SO 1029969 我能够获得最大斑点的SHA1列表。然后,我使用 SO 460331 中的脚本查找blob ...和五个最大的不存在,虽然小斑点被发现,所以我知道脚本正在工作。



我认为这些博客是二进制文件从发布分支,并且他们在删除那个分支后以某种方式留下了。什么是摆脱他们的正确方法?

解决方案

...我可以向你介绍这个有用的脚本, git-gc-all ,保证删除所有你的git垃圾,直到它们可能会出现额外的配置变量:

  git -c gc.reflogExpire = 0 -c gc.reflogExpireUnreachable = 0 -c gc.rereresolved = 0 \ 
-c gc.rerereresolved = 0 -c gc .pruneExpire = now gc$ @

您可能还需要先运行这些东西,哦亲爱的,git很复杂!!

  git remote rm origin $ b $ r 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

我把所有这在一个脚本,在这里:



http://sam.nipl.net/b/git-gc-all-ferocious



编辑:您可能还需要删除一些标签,谢谢Zitrax:

  git tag | xargs git tag -d 


I have a GitHub repo that had two branches - master & release.

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

First I deleted the remote release branch, via git push origin :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.

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, with no luck.

By following Charles Bailey's instructions at SO 1029969 I was able to get a list of SHA1s 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.

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?

解决方案

... and without further ado, may I present to you this useful script, git-gc-all, guaranteed to remove all your git garbage until they might come up extra config 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, oh dear, git is complicated!!

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

I put all this in a script, here:

http://sam.nipl.net/b/git-gc-all-ferocious

edit: You might also need to remove some tags, thanks Zitrax:

git tag | xargs git tag -d

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

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