【问题标题】:.git/objects is bigger then the entire git repo, how to resolve the issue?.git/objects 比整个 git repo 大,如何解决这个问题?
【发布时间】:2020-06-11 22:54:22
【问题描述】:

我不小心上传了一些不必要的文件到我的 git repo。不知何故,我从本地 repo 中删除了所有不必要的文件,并将所有更改强行推送到 GitHub,它起作用了,所有文件都完全消失了。

但是我遇到了一个奇怪的问题,当我使用下载按钮通过 GitHub 页面下载 git repo 时:

size of my repo is 500kbs

当我通过 git clone 克隆 repo 时,终端输出显示:

it dowloaded  around 130MB

但是,最后,在下载完成后(解压 500kb 文件后这个大小似乎还可以):

git repo size is around  1.3MB.

当我通过 UI 检查目录的属性时:

it shows 1.3MB

当我尝试通过命令提示符检查属性时(du -sh /Dir):

it shows size 130MB 

我尝试进行更多探索,然后发现 .git/object 缺少大约 130MB 的大块。

我正在尝试了解问题所在,以及如何解决问题。

谢谢。

【问题讨论】:

  • 您是否使用git filter-branch 或git filter-repo 从所有提交中删除了不必要的文件?如果没有,文件数据仍然被旧的提交引用并存在于 git 数据库中。

标签: git github gitlab


【解决方案1】:

我将首先检查清除存储库历史的结果:使用新工具 git filter-repo which replaces BFG and git filter-branch。

git filter-repo --strip-blobs-bigger-than 10M

然后检查.git 文件夹的大小。
确保您的回购历史记录中不需要这些大文件。

注意:如果您在运行上述命令时收到以下错误消息:

Error: need a version of `git` whose `diff-tree` command has the `--combined-all-paths` option`

这意味着你必须update git。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-07
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 2011-02-12
    相关资源
    最近更新 更多