Git — There are too many unreachable loose objects

涓 / Lynn Chang
Lynn’s dev blog
Published in
2 min readApr 28, 2021
Photo by Christin Hume on Unsplash

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 showed 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 that exist but that are never directly used.

  • Dangling blob

A change that made it to the staging area/index but never got committed.

  • Dangling commit

A commit that isn’t directly linked to by any child commit, branch, tag or other reference.

(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 hard disk.

How to solve too many “dangling objects“ problem ?

  1. git fsck

This will verifies the connectivity and 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.

--

--

涓 / Lynn Chang
Lynn’s dev blog

A software engineer who loves writing and cares about mental health and life meaning.