如何减少git大小(通过删除本地旧提交)? [英] How to reduce git size (by deleting local old commits)?

查看:60
本文介绍了如何减少git大小(通过删除本地旧提交)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git存储库,它的源大小只有1MB,但是有300MB .git文件夹.其中有10000多个提交.

I have a git repository which source size is only 1MB, but a 300MB .git folder. There's 10000+ commits in it.

我想通过仅在本地保留几个较新的提交来使本地存储库较小,我该怎么做.

I would like to keep my local repository small by keeping only several newer commits in local, how can I do that.

推荐答案

1.9版之前的Git版本在处理浅表克隆方面不是特别出色.如果您走那条路线,请确保您使用的是git的最新版本.

Versions of Git prior to 1.9 are not particularly great at how they deal with shallow clones. If you go that route make sure you are using a recent version of git.

通常,提交很小,即使10,000次提交也不会占用太多空间.但是,它们指向的斑点可能会出现.

Normally commits are very small, and even 10,000 commits shouldn't eat up very much space. The blobs they point to may however.

假设您无法永久更改历史记录

Presuming you cannot permanently alter history

尝试重新打包以压缩对象.

Try an aggressive repack to compress the objects.

git repack -a -d --depth=250 --window=250

使用共享对象存储库(如果可行),方法是使用 .git/objects/info/alternates

Use a shared object store if that is viable for your situation by using .git/objects/info/alternates

如果这些都不起作用并且历史记录已修复,请尝试使用 git clone --depth 进行浅表克隆.请务必阅读克隆帮助页面,并了解您在做什么.

If those don't work and history is fixed then try a shallow clone with git clone --depth. Be sure to read the clone help page and understand what you are doing though.

这篇关于如何减少git大小(通过删除本地旧提交)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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