Git - There are too many unreachable loose objects

To Reproduce:

  • 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?

  1. git fsck

This will verify the connectivity, validity of the object and list those dangling objects if they exist.

2. git gc --prune=now

  • git prune

This will remove dangling objects.

  • git gc

-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.


Reference: