9

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
5
  • 2
    Clean out the reflogs, that's probably where things are hiding.
    – torek
    Commented Dec 15, 2014 at 17:44
  • possible duplicate of Reduce git repository size
    – Andrew C
    Commented Dec 15, 2014 at 18:24
  • @AndrewC That is what I tried to use and where I got the gc command above, but at the time it made no mention of the reflog.
    – vossad01
    Commented Dec 15, 2014 at 18:28
  • 1
    I realized it was a circular reference after I marked it. Whoops. You'd think it would be somewhere but the stack overflow searching is so terrible.
    – Andrew C
    Commented Dec 15, 2014 at 18:41
  • No worries. The great part about this is the answer for that question has now been updated which should keep more people from experiencing this.
    – vossad01
    Commented Dec 15, 2014 at 20:34

1 Answer 1

10

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.