How can I get rid of "Lost heads"?
Asked Answered
B

2

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.

Bubonocele answered 23/2, 2013 at 19:8 Comment(0)
P
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.

Ptolemy answered 23/2, 2013 at 19:51 Comment(4)
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.Bubonocele
After some time it's difficult to find my commit when I have hundreds of them. That would be valid reason for me.Nert
@pevik, if many lost heads make the Log confusing, just uncheck the option and only when needed recheck again.Ptolemy
@mstrap, and is there any way how to do it with plain git (not in SmartGit)?Nert
C
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://mcmap.net/q/12714/-how-to-remove-unreferenced-blobs-from-my-git-repository

Caboodle answered 11/7, 2018 at 5:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.