为什么我的git存储库如此之大? [英] Why is my git repository so big?
问题描述
145M = .git / objects / pack /
我写了一个脚本,将每次提交和提交的差异大小加起来,每个分支的尖端。我得到了129MB,这是没有压缩,没有考虑分支机构中的相同文件以及分支机构之间的共同历史记录。
Git考虑到了所有这些因素,所以我期望得到更多较小的存储库那么为什么.git这么大?
我已经完成:
git fsck --full
git gc --prune = today --aggressive
git repack
要回答关于多少个文件/提交,我有19个分支,每个分支大概有40个文件。
287提交,使用:
git log --oneline --all | wc -l
不应该花费10兆字节来存储有关此信息。
git remote update
)。删除不需要的远程参考,分支和标签后,我的存储库中仍有1.4GB(!)的浪费空间。我只能用 git clone file:/// path / to / repository
克隆它。请注意,在克隆本地存储库时, file://
会产生不同的效果 - 只有被引用的对象被拷贝到整个目录结构中,而不是整个目录结构中。 b $ b
编辑:这是Ian的一个班轮,用于重新创建新回购中的所有分行:
d1 =#原始回购
d2 =#新回购(必须已经存在)
cd $ d1
for $ in $(git branch | cut -c 3-)
do
git checkout
$ bx = $(git rev-parse HEAD)
cd $ d2
git checkout -b $ b $ x
cd $ d1
完成
145M = .git/objects/pack/
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 takes all those things into account so I would expect much much smaller repository. So why is .git so big?
I've done:
git fsck --full
git gc --prune=today --aggressive
git repack
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
It should not be taking 10's of megabytes to store information about this.
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.
Edit: 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屋!