Git - There are too many unreachable loose objects
git cm 'some_message'
commit successfully, but git showed the message below:
error: The last gc run reported the following. Please correct the root
cause and remove gc.log.
Automatic cleanup will not be performed until the file is removed.
warning: There are too many unreachable loose objects; run 'git prune'
to remove them.
Why git shows this error message?
You are seeing this error because you have too many dangling commits for git to automatically clean up.
What is "dangling commit" & "dangling blob"?
Dangling objects exist but they are never directly used.
- Dangling blob
A change that made it to the staging area/index but never got committed.
- Dangling commit
A commit isn’t directly linked to any child commit, branch, tag, or other references.
(Information from: Stack overflow)
What will “dangling objects” have an influence on?
Actually, the worst situation is dangling objects take up too much space of the hard disk.
How to solve the "too many dangling objects" problem?
This will verify the connectivity, validity of the object and list those dangling objects if they exist.
git gc --prune=now
This will remove dangling objects.
-prune=<date> Prune loose objects older than date (default is 2 weeks ago, overridable by the config variable gc.pruneExpire). — prune=now prunes loose objects regardless of their age and increases the risk of corruption if another process is writing to the repository concurrently; see “NOTES” below. — prune is on by default.