How can I trigger garbage collection on a Git remote repository?
As we know, we can periodically run git gc
to pack objects under .git/objects
.
In the case of a remote central Git repository (bare or not), though, after many pushes, there many files under myproj.git/objects
; each commit seems to create a new file there.
How can I pack that many files? (I mean the ones on the remote central bare repository, not on local clone repository.)
The remote repo should be configured to run gc as needed after a commit is made. See the documentation of gc.auto in git-gc and git-config man pages.
However, a remote repo shouldn't need all that much garbage collection, since it will rarely have dangling (unreachable) commits. These usually result from things like branch deletion and rebasing, which typically happen only in local repos.
So gc is needed more for repacking, which is for saving storage space rather than removing actual garbage. The gc.auto variable is sufficient for taking care of this.
While you should have some process that takes care of this periodically, automatically, it's no problem run
git gc
on a bare repository
git@domU:/pix/git/repositories/abd.git$ ls -l
total 28
drwxrwxr-x 2 git git 6 2010-06-06 02:44 branches
-rw-rw-r-- 1 git git 66 2010-06-06 02:44 config
-rw-r--r-- 1 git git 23 2011-03-15 18:19 description
-rw-rw-r-- 1 git git 23 2010-06-06 02:44 HEAD
drwxrwxr-x 2 git git 4096 2010-06-06 02:44 hooks
drwxrwxr-x 2 git git 20 2010-06-06 02:44 info
drwxrwxr-x 260 git git 8192 2010-09-01 00:26 objects
drwxrwxr-x 4 git git 29 2010-06-06 02:44 refs
$ git gc
Counting objects: 3833, done.
Compressing objects: 31% (1085/3500)...
This question should shed some light on how often you should run garbage collection.
The easiest option would be to use a scheduled task in windows or a cron job in Unix to run git gc
periodically. This way you don't even need to think about it.
上一篇: 删除或撤消对远程Git仓库的推送