如何从一个Gi​​t仓库删除未使用的对象? [英] How to remove unused objects from a git repository?

查看:349
本文介绍了如何从一个Gi​​t仓库删除未使用的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心加,致力并推动一个巨大的二进制文件和我的最新承诺一个Git仓库。

我怎样才能让Git的删除是/是为创建对象(S)犯下所以我的的.git 目录收缩到再次一个健全的大小?

修改:谢谢您的回答;我试了好几种解决方案。无工作。例如从GitHub一个移除了历史上的文件,但的.git 目录大小并没有减少:

  $ Badfiles文件= $(找到test_data型的F -exec回声-n'{}'\\;)$ git的过滤分支--index过滤器混帐室射频--cached  - 忽略UNMATCH $ Badfiles文件HEAD
重写14ed3f41474f0a2f624a440e5a106c2768edb67b(66分之66)
RM'test_data /图像/ 001.JPG
[...剪断...]
RM'test_data /图像/ 281.jpg
参考裁判/头/主'被改写$ git的日志-p#看起来不错$室射频的.git /参/原厂/
$ git的引用日志 - 所有到期
$ git的GC --aggressive --prune
计数对象:625,完成。
最多可使用2个线程三角洲COM pression。
玉米pressing对象:100%(598分之598)完成。
写作对象:100%(625分之625)完成。
总计625(增量351),再用0(0增量)$杜-HS的.git
174M的.git
$#175仍:-( MB


解决方案

我在别处回答了这个,因为我很骄傲在这里复制!

...并事不宜迟,我可以present你这个有用的脚本,混帐-GC-一切,保证移除所有的git的垃圾,直到他们可能会拿出额外的配置变量:

混帐-c gc.reflogExpire = 0 -c gc.reflogExpireUnreachable = 0 \\
  -c gc.rerereresolved = 0 -c gc.rerereunresolved = 0 \\
  -c gc.pruneExpire =现在GC$ @

该--aggressive选项可能会有所帮助。

请注意:这将删除所有未引用一样的东西,所以不要来哭,我如果以后决定,你想保留其中的某些

您可能还需要运行类似这些第一,哦,亲爱的,Git是复杂的!

远程Git RM起源
室射频的.git /参/原厂/ git的/参/遥控器/ git的/ * _ HEAD的.git /日志/
混帐的for-each-REF --format =%(refname)裁判/原厂/ |
  xargs的-n1 --no-运行,如果空的git更新-REF -d

我把这一切在一个脚本,在这里:

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

I accidentally added, committed and pushed a huge binary file with my very latest commit to a Git repository.

How can I make Git remove the object(s) that was/were created for that commit so my .git directory shrinks to a sane size again?

Edit: Thanks for your answers; I tried several solutions. None worked. For example the one from GitHub removed the files from the history, but the .git directory size hasn't decreased:

$ BADFILES=$(find test_data -type f -exec echo -n "'{}' " \;)

$ git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $BADFILES" HEAD
Rewrite 14ed3f41474f0a2f624a440e5a106c2768edb67b (66/66)
rm 'test_data/images/001.jpg'
[...snip...]
rm 'test_data/images/281.jpg'
Ref 'refs/heads/master' was rewritten

$ git log -p # looks nice

$ rm -rf .git/refs/original/
$ git reflog expire --all
$ git gc --aggressive --prune
Counting objects: 625, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (598/598), done.
Writing objects: 100% (625/625), done.
Total 625 (delta 351), reused 0 (delta 0)

$ du -hs .git
174M    .git
$ # still 175 MB :-(

解决方案

I answered this elsewhere, and will copy here since I'm proud of it!

... 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 with 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 "$@"

The --aggressive option might be helpful.

NOTE: this will remove ALL unreferenced thingies, so don't come crying to me if you decide later that you wanted to keep some of them!

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

这篇关于如何从一个Gi​​t仓库删除未使用的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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