I'm using a local Git repo that uses our company's SVN repo as origin.
I often receive the message:
error: The last gc run reported the following. Please correct the root cause and remove .git/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.
Indeed removing .git/gc.loc
and calling git prune
fixes the issue.
However, in a comment to VonC's answer to How to skip "Loose Object" popup when running 'git gui' by Michael Donohue, Michael Donohue states:
[...] I do like the safety aspect of keeping the loose objects around for two weeks, should I want to go back and look at some old revisions [...]
In an answer (also by VonC) to Whole team gets 'too many unreachable loose objects' messages — a question aboutgitlabissue with loose objects after moving from SVN to git — by jlengrand, VonC writes:
- ran git prune and prayed it didn't break things (which it thankfully didn't)
So, I assume git prune
is a dangerous operation that can destroy things.
To safely deal with the "too many unreachable loose objects"-message I have the following questions:
What causes these loose objects (see man git-fsck
about unreachable object and see torek's answer — about the inner workings of git objects and hashes and git gc
, git prune
, and git repack
— to What does git do when we do : git gc - git prune by Lyes CHIOUKH)?
Is it only git svn push
that:
- reads the git commit object,
- sends it to the SVN server,
- retrieves the stored SVN revision,
- creates a fresh git commit object that reflects the SVN revision,
- replaces the HEAD pointer to the commit from step 1 with one pointing to the commit of step 4, and
- leaves the original commit as a loose object.
Does this indeed cause the loose commits?
Does this cause all loose commits (I also do some git tree manipulation of stuff not yet in SVN such as git stash
, git cherry-pick
, git rebase
, and git reset
)?
When may I need these loose objects?
What is a good policy for using git prune
on my personal git repo?