为什么 git 不会进一步减小存储库的大小? [英] Why won’t git further reduce the repository size?

查看:18
本文介绍了为什么 git 不会进一步减小存储库的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只有一个提交的存储库,其签出大小为 95M.但是,我无法获得低于 213M 的 .git 文件夹大小.但是,如果我创建一个具有相同文件内容的新存储库,我会得到一个只有 38M 的 .git 文件夹.

I have a repository with only one commit that has a checked out size of 95M. However, I cannot get the .git folder size below 213M. However, if I create a new repository with the same file contents, I get a .git folder of only 38M.

有没有办法让 git 重建它的对象,以便通过创建一个新的存储库使大小更符合图形?

Is there a way to git to rebuild its objects in such a way as to get the size more in line with the figure from creating a new repository?

我尝试了 git gc --prune=now --aggressivegit repack -adf --window=250 --depth=250 来减小存储库大小.他们将存储库从原来的 220M 降低了.

I tried both git gc --prune=now --aggressive and git repack -adf --window=250 --depth=250 to reduce the repository size. They brought the repository down from the original 220M.

我想 git 必须在某个地方保存一个引用以防止垃圾收集,但我不知道它们会在哪里.我已经删除了所有遥控器和分支,除了refs"下的当前分支之外,我没有看到任何其他内容

I imagine git must be keeping a references somewhere that prevents garbage collection, but I do not know where they would be. I have removed all remotes and branches and I do not see anything other than my current branch under 'refs'

$ ls -R .git/refs
.git/refs/:
heads  tags

.git/refs/heads:
master

.git/refs/tags:

我从具有较长历史的现有存储库创建了存储库.我使用 checkout --orphan 创建了一个新的无基础分支,然后进行了提交以使用存储库的状态创建一个新的提交.然后我在运行 gc 之前删除了原始分支并删除了遥控器.

I created the repository from an existing one with longer history. I used checkout --orphan to create a new baseless branch then did a commit to create a new commit with the state of the repository. I then deleted the original branch and removed the remotes before running gc.

$ git --version
git version 1.9.4.msysgit.0

推荐答案

运行:

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

将文件夹缩小到 27M.感谢@torek 建议清理 reflog 的评论!

brought the folder down to 27M. Thanks to @torek for the comment suggesting cleaning the reflog!

我曾认为 reflog 不是问题,因为如果我运行 git reflog 我只会看到一个条目,即我的单个提交.为了回应@torek 的建议,我发现 如何从一个 git 存储库? 这是我找到清除 reflog 的命令的地方.

I had thought the reflog was not an issue because if I ran git reflog I only saw one entry, my single commit. In response to @torek's suggestion I found How to remove unused objects from a git repository? which is where I found the command for clearing the reflog.

这篇关于为什么 git 不会进一步减小存储库的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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