通过删除旧提交压缩回购 [英] Compact repo by removing old commits

查看:112
本文介绍了通过删除旧提交压缩回购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



类似于 git clone --depth的方式,可以通过删除旧提交的本地副本来减少回购大小5 产生一个只有最近提交数据的小型本地克隆。



回购包含千兆字节的游戏资产,这些资产在过去被多次覆盖。 / p>

编辑:我不想清除过去的历史记录;我希望历史记录与远程记录保持一致,但我不希望旧提交在本地存储并可用。

解决方案

不幸的是,仅保留历史记录中的最新提交并且完全可用存储库是不可能的。浅拷贝是不完全可用的,因为它不能被提交到。



换句话说,由于git将数据保存在对象存储中的方式,因此没有多个选项而不是从头开始重写历史记录。

可能最简单的方法是将所有当前游戏资产文件复制到git存储库之外的某个位置,然后使用 git filter-branch 作为此处所述来移除您的来自历史的资产,就像它从未存在过。最后,将资产复制回合适的位置并再次提交。这将以游戏资产只出现在最近的提交中的方式来重写你的历史。



然而,它仍然不会回收磁盘空间,直到你这样做:

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


Is there a way to reduce repo size by removing local copy of data about old commits?

Similar to how git clone --depth 5 produces a small local clone with only recent commit data.

The repo contains gigabytes of game assets which were overwritten multiple times in past.

Edit: I don't want to just purge the past history; I want the history to remain consistent with the remote, but I don't want old commits to be locally stored and available.

解决方案

Unfortunately, it is NOT possible to keep only most recent commits in history and have fully usable repository. Shallow copy is NOT fully usable because it cannot be committed into.

In other words, because of the way git keeps data in object store, you don't have many options other than rewriting history from scratch.

Probably easiest approach is to make a copy of all current game asset files somewhere outside of git repository, then use git filter-branch as described here to remove your assets from history, like it never existed. Finally, copy assets back into their rightful place and commit them once again. This will rewrite your history in a way that game assets only appear in most recent commit.

However, it will still not reclaim disk space though until you do:

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

这篇关于通过删除旧提交压缩回购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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