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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With