11

In my first attempt to do something with git I used GitHub for Windows. As it is simple and quite primitive tool I decided to try SmartGit. As I was looking around I discovered I have leftovers over my tests - something called "lost heads". How can I get rid of this garbage? It seemed that

git gc --prune=now

or something similar should work, but nothing changed. I tried googling, but everybody was trying to do reverse thing - restore lost commits from lost head or something similar.

2 Answers 2

10

According to the man page, git gc will not garbage collect files which are referenced through the 'reflogs' (.git/logs/<ref-name> files in your repository). These HEADs are exactly what SmartGit/Hg displays and when you remove these logs, the unreferenced commits should be collected by a git gc --prune=now.

Warning Unless there is no really good reason to completely get rid of these commits (like removing sensitive data), you shouldn't do that -- maybe some time later your might be interested in exactly one of these commits. At least, reclaiming disk space is no good reason, in my opinion.

4
  • 1
    reclaiming disk space is not my reason (my git repository takes less than 0,01% of available space) - I want to get rid of "aaaeaeae test 2626" hanging everywhere. Commented Feb 23, 2013 at 19:56
  • After some time it's difficult to find my commit when I have hundreds of them. That would be valid reason for me.
    – pevik
    Commented Oct 24, 2014 at 6:19
  • @pevik, if many lost heads make the Log confusing, just uncheck the option and only when needed recheck again.
    – mstrap
    Commented Oct 24, 2014 at 13:23
  • @mstrap, and is there any way how to do it with plain git (not in SmartGit)?
    – pevik
    Commented Oct 29, 2014 at 9:02
0

this will remove more than just git gc --prune=now:

git -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 -c gc.rerereresolved=0 \
-c gc.rerereunresolved=0 -c gc.pruneExpire=now gc "$@"

source: https://stackoverflow.com/a/14728706/1069083

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