Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
530 views
in Technique[技术] by (71.8m points)

garbage collection - Why won’t git further reduce the repository size?

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.

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?

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.

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:

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Running:

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

brought the folder down to 27M. Thanks to @torek for the comment suggesting cleaning the 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...