通过清除存储库历史记录来免除磁盘空间 [英] git free disk space by clearing repository history

查看:135
本文介绍了通过清除存储库历史记录来免除磁盘空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在和一些朋友一起工作,我们都是新来的git,其中一人提交了大量外部二进制文件,这会降低存储库的速度,并占用大量的磁盘空间。

b
$ b

我们刚刚开始这个项目,除了自述文件之外,没有什么重要的东西。所以我们想要做的就是清理版本库历史到当前状态。

 所以基本上它看起来是这样的:

主管 - > A - > B - > C总磁盘大小45 MB,1个文件,300个已删除文件

我们希望这样:

头 - >总磁盘大小为1 kB,1个文件,0个已删除文件

显而易见的解决方案是创建一个新的存储库,并将自述文件复制到新的存储库中。然而,如果有GIT命令可以做到这一点,我想要了解教育/好奇心。



我一直在试验Rebase命令,但它看起来像它仍然保留着旧的历史和他们的数据,这使我感到困惑,因为如果重新定位不修剪数据库中的数据,那么你可能不会使用它。



我一直在Google上搜索一些其他的在这个问题上的帖子,以及我怀疑你不能用git做到这一点。不过,我想确认一下。



是的,它是github上的远程目录



感谢任何人帮助。



所以对于我的解决方案,我选择了:

  rebase使用tortoisegit 
压扁所有提交
然后使用git bash:
git reflog expire --all --expire -reachable = now
git gc --aggressive --prune = now
git push origin master --force

它看起来不像本地资料库历史记录想要缩小磁盘大小。但是,再次克隆存储库会显示所需的结果和磁盘大小。版本库日志也是如此。



感谢您提供有用的回复。有趣的Rebase看起来非常强大。

解决方案

重新绑定( git rebase -i --root ,如果你没有恢复坏的提交,只是删除它的行,如果你这样做,用恢复提交压缩坏的提交)或使用过滤器分支将清除你的分支的历史数据,但不会它完全从存储库中消失。



这是因为,出于安全性和可追踪性的原因,git保留一个reflog(用 git log -g ),它跟踪你所做的每一次提交,不管它是否仍然是祖先图表的一部分。



克隆过滤后的回购不会克隆隐藏数据,你也可以用这些命令就地删除它:

  git reflog expire --all --expire -reachable = now 
git gc --aggressive --prune = now

这些命令不是通常推荐,并且无关的提交将在30天后过期,但是罪恶您的存储库实际上是新的,您不会冒太大风险。

so I'm working with some friends and we are all new to git and one of them committed a large amount of external binary files that slows down the repository, and takes up a large disk-space.

We've just started the project so there's nothing important in it really except a readme file. So what we'd like to do is to Clear the repository history to the current state.

So basicly it looks this:

Head -> A -> B -> C    total disk size 45 MB, 1 file, 300 deleted files

And we want this:

Head -> A              total disk size 1 kB, 1 file, 0 deleted files

The obvious solution would be to create a new repository and just copy the readme file into the new repository. However I'd like to learn for educational/curiosity if there's GIT command that can do this.

I've been experimenting with the Rebase command, but it seems like it still keeps old history and their data, which confuses me since if rebaseing doesnt prune data from the repository then you might aswell not use it.

I've been googling some other posts on this issue, and im suspecting that you can't do this with git. However I'd like to confirm that.

And yes it's a remote directory on github

Thanks for any help.

So for my solution i chose to do:

rebase using tortoisegit
squash all commits
then using git bash:
git reflog expire --all --expire-unreachable=now
git gc --aggressive --prune=now
git push origin master --force

It doesn't seem like the local repository history wants to shrink in disk size. However cloning the repository again shows the desired results and disk size. And the repository log does too.

Thanks for the helpful replies. Interesting Rebase seems very powerful.

解决方案

Rebasing (git rebase -i --root, if you didn't revert the bad commit just delete its line, if you did, squash the bad commit with the revert commit) or using filter-branch will clear the data from your branch's history, but won't make it disappear from the repository entirely.

This is because, for safety and tracability reasons, git keeps a reflog (visible with git log -g) which tracks every commit you did, whether or not it's still part of the ancestry graph.

Cloning the filtered repo won't clone the hidden data, and you can also remove it in-place with these commands:

git reflog expire --all --expire-unreachable=now
git gc --aggressive --prune=now

Those commands aren't normally recommended and the unreferenced commits would expire in 30 days anyway, but since your repository is practically new you're not risking much.

这篇关于通过清除存储库历史记录来免除磁盘空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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