Here I want to share a solution to the following Git error:
There are too many unreachable loose objects. This usually happens when Git cannot cleanup all dangling commits as they are too many. Regarding the solution, it includes my favorite operation so far, removing dangling objects. To be clear, dangling commits and blobs are usually referred as dangling Git objects.
Step 1. List dangling commits:
git fsck --lost-found | grep "^dangling commit" | sed
git fsckverifies connectivity and validity of the Git objects too.
- Adding option
--lost-foundwill save dangling commits under
.git/lost-found/commit. Blobs are stored under
Step 2. Initiate the Git garbage collector as it will remove the dangling objects:
git gc --aggresive --prune=now
Related: Git gc.