Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top