我目前的基地总规模大约是。200 mb。
但是我的。git文件夹有惊人的5GB(!)。因为我把我的工作推到一个外部服务器,我不需要任何大的本地历史…
如何缩小。git文件夹以释放笔记本上的一些空间?我可以删除超过30天的所有更改吗?
我目前的基地总规模大约是。200 mb。
但是我的。git文件夹有惊人的5GB(!)。因为我把我的工作推到一个外部服务器,我不需要任何大的本地历史…
如何缩小。git文件夹以释放笔记本上的一些空间?我可以删除超过30天的所有更改吗?
当前回答
5GB vs 200MB有点奇怪。尝试运行git gc。
但是,除非您将存储库拆分为模块,否则您无法减小.git目录的大小。
git repo的每个克隆都是一个完整的存储库,可以充当服务器。这是分布式版本控制的基本原理。
其他回答
以下是git的创建者Linus对如何缩小git回购的看法:
The equivalent of "git gc --aggressive" - but done *properly* - is to do (overnight) something like git repack -a -d --depth=250 --window=250 where that depth thing is just about how deep the delta chains can be (make them longer for old history - it's worth the space overhead), and the window thing is about how big an object window we want each delta candidate to scan. And here, you might well want to add the "-f" flag (which is the "drop all old deltas", since you now are actually trying to make sure that this one actually finds good candidates.
来源:http://gcc.gnu.org/ml/gcc/2007-12/msg00165.html
这将摆脱二进制数据是孤儿在我的回购?“git重新打包”将不会删除你已经签入repo然后删除它的图像或二进制数据。要从你的回购中永久删除这些数据,你必须重写你的历史记录。一个常见的例子是当你不小心在git中检入你的密码。你可以回去删除一些文件,但你必须重写从那时到现在的历史记录,然后强制将新的repo推到你的原点。
5GB vs 200MB有点奇怪。尝试运行git gc。
但是,除非您将存储库拆分为模块,否则您无法减小.git目录的大小。
git repo的每个克隆都是一个完整的存储库,可以充当服务器。这是分布式版本控制的基本原理。
尝试了以上方法,在我的情况下没有任何工作(在git推送期间,我不小心杀死了git进程),所以我最终不得不删除回购并再次克隆它,现在.git文件夹是正常大小。
最好的选择是使用BFG Repo Cleaner (BitBucket推荐使用,其他选项要快得多): https://rtyley.github.io/bfg-repo-cleaner/
我也尝试过使用史蒂夫·洛雷克的解决方案,它也有效:https://web.archive.org/web/20190207210108/http://stevelorek.com/how-to-shrink-a-git-repository.html
我更多地将git用作同步机制,而不是版本历史。所以我对这个问题的解决方案是确保我所有的当前源都处于令人满意的状态,然后删除.git并重新初始化repo。磁盘空间问题解决。:-)历史消失了:-( 我这样做是因为我的回购是在一个小的u盘上。我不想要也不需要我的全部历史。 如果我有一种截断历史的方法,我就会使用它。
If I were interested in keeping my history I would archive the current repository. At some point later I could clone the original repository, copy over all the changes from the new repo (let's assume I haven't done much (any) renaming or deleteing). And then make one big commit that would represent all the changes made in the new repo as a single commit in the old repo. Is it possible to merge the histories? Maybe if I used a branch and then deleted the objects I didn't need. (I dont' know enough about git internals to start fooling around like that).