Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 571
vossad01 Avatar asked Dec 15 '14 17:12

vossad01


1 Answers

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.

like image 119
vossad01 Avatar answered Nov 11 '22 08:11

vossad01