I have encountered my first request to run git gc. The message I received on my last commit was:
warning: There are too many unreachable loose objects; run 'git prune' to remove them.
and ...
You may also run "git gc" manually. See "git help gc" for more information.
So my question is do I run git gc --aggressive
, --auto
--prune
or --quiet
.
Essentially I am concerned that I might lose any commit history or disrupt my master branch in any way?
Any recommendations?
Running git gc manually should only be needed when adding objects to a repository without regularly running such porcelain commands, to do a one-off repository optimization, or e.g. to clean up a suboptimal mass-import.
Garbage collection is run automatically on several frequently used commands: git pull. git merge. git rebase.
We run git gc at most once per day, triggered automatically by a push.
Again, these are all implementation details that git gc handles and git prune should not be used standalone. The above command will force expire all entries to the reflog that are older than now. This is a brutal and dangerous command that you should never have to use as casual Git user.
In general, git gc
is safe to run. It won't throw away any commits reachable from any named reference. Depending on how you've set the appropriate expiration variable (e.g., gc.pruneexpire
, gc.reflogexpire
, etc.) it will possibly throw away commits that are only reachable from the reflog, or aren't reachable at all. I let git gc
decide when to prune on its own (looking at those expire settings) and usually do a git gc --aggressive
. It displays some stats while it's working. If you don't want to see those, then add --quiet
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With