Borek Bernard
Borek Bernard

Reputation: 53251

`git gc` without packing objects?

I'd like to remove objects (.git/objects) from my repository that are no longer referenced by any refs, but I don't want to pack to pack files.

I tried git gc --no-prune but it still removed all objects from my repo and left only packfiles (git count-objects reports "0 objects, 0 kilobytes").

Upvotes: 5

Views: 292

Answers (1)

torek
torek

Reputation: 488213

git gc is a wrapper for a whole series of smaller maintenance operations:

  • git reflog expire
  • git repack
  • git prune-packed (actually done by git repack automatically when you use -d)
  • git prune
  • any others I may have forgotten

and git prune is the one that specifically removes unreferenced objects. Note that git gc supplies an expiry time so that git prune won't remove unreferenced objects that are still being constructed. If you have no active Git commands that might be constructing objects, and don't want to provide the gc default grace period, you don't need to worry about this.

Upvotes: 8

Related Questions