You can find Git project objects under
.git/objects. When dealing with managing objects using
git fsck and
git gc commands, you might stumble upon the following types of “failed” objects: loose, dangling and unreachable. Let’s see what’s that all about.
Loose object is every Git object which is stored under a two-digit subdirectory under
.git/objects. For instance a loose object is the following one:
Basically these objects are still not compressed together under a single file.
Unreachable object is a Git object which is inaccessible from any other commit, tag or reference. To list unreachable objects, run:
git fsck --unreachable.
Dangling object is an unreachable Git object that’s not pointed at (referenced) by anything including other unreachable objects. To recap, a dangling object = unreachable + no one points to it.
To list dangling objects, run:
git fsck --dangling. Since a dangling object could be commit or blob as well, to list the dangling commits only, run:
git fsck --lost-found | grep "^dangling commit" | sed
Note(s): Adding option
--lost-found will save dangling commits under
.git/lost-found/commit. Blobs are stored under
Now, bare with me. A loose object can be unreachable or dangling too.
If you want to get rid of from all these objects run:
git gc --prune=now. Related: Git gc.