为什么我的 git 仓库这么大? [英] Why is my git repository so big?

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

问题描述

145M = .git/objects/pack/

145M = .git/objects/pack/

我编写了一个脚本,将每个提交的差异大小与从每个分支的尖端向后的提交相加.我得到 129MB,没有压缩,也没有考虑跨分支的相同文件和分支之间的共同历史.

I wrote a script to add up the sizes of differences of each commit and the commit before it going backwards from the tip of each branch. I get 129MB, which is without compression and without accounting for same files across branches and common history among branches.

Git 将所有这些都考虑在内,所以我希望存储库要小得多.那么为什么 .git 这么大?

Git takes all those things into account so I would expect much much smaller repository. So why is .git so big?

我已经完成了:

git fsck --full
git gc --prune=today --aggressive
git repack

为了回答有多少文件/提交,我有 19 个分支,每个分支大约有 40 个文件.287 次提交,发现使用:

To answer about how many files/commits, I have 19 branches about 40 files in each. 287 commits, found using:

git log --oneline --all|wc -l

存储相关信息不应占用 10 兆字节.

It should not be taking 10's of megabytes to store information about this.

推荐答案

我最近把错误的远程仓库拉到了本地(git remote add ...git remote update).删除不需要的远程引用、分支和标签后,我的存储库中仍有 1.4GB (!) 浪费的空间.我只能通过使用 git clone file:///path/to/repository 克隆它来摆脱它.请注意,file:// 在克隆本地存储库时会产生不同的影响 - 仅复制引用的对象,而不是整个目录结构.

I recently pulled the wrong remote repository into the local one (git remote add ... and git remote update). After deleting the unwanted remote ref, branches and tags I still had 1.4GB (!) of wasted space in my repository. I was only able to get rid of this by cloning it with git clone file:///path/to/repository. Note that the file:// makes a world of difference when cloning a local repository - only the referenced objects are copied across, not the whole directory structure.

这是 Ian 的一个用于在新存储库中重新创建所有分支的衬垫:

Here's Ian's one liner for recreating all branches in the new repo:

d1=#original repo
d2=#new repo (must already exist)
cd $d1
for b in $(git branch | cut -c 3-)
do
    git checkout $b
    x=$(git rev-parse HEAD)
    cd $d2
    git checkout -b $b $x
    cd $d1
done

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

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