Forcing Remote Repo to Compress (GC) with Git

不羁的心 提交于 2019-11-29 04:02:29

If you can't run git gc yourself, you're going to have to trick it into running automatically. You won't have quite such full control over it then, but you should at least be able to get it to run.

git gc --auto is run by several commands; the relevant one here is receive-pack, which is run on the remote to receive a pack as part of a push. gc --auto only repacks when there are enough loose objects; the cutoff is determined by the config parameter gc.auto, and defaults to 6700.

If you have access to the remote's gitconfig, you could set that cutoff to 1 temporarily. There should pretty definitely be at least 1 loose object in the repo, so that should cause gc --auto to do its thing the next time you push.

If you don't have access to the remote's gitconfig, all I can think to do is artificially create a bunch of loose objects. You could do that by creating a branch, committing a bunch of tiny files (with different content) to it, pushing the branch to the remote, then deleting the branch from the remote. (Important to vary the content, or they'll just use the same blobs.) Rinse and repeat.

That's really a problem that they need to solve on their end. They can do it with a post-receive hook or a cron job or something similar, but if they're supposed to be maintaining your repositories, that's kind of part of it for numerous reasons.

takeshin

Form git-gc man page:

Some git commands may automatically run git gc; see the --auto flag below for details.

And further:

--auto

With this option, git gc checks whether any housekeeping is required; if not, it exits without performing any work. Some git commands run git gc --auto after performing operations that could create many loose objects.

Housekeeping is required if there are too many loose objects or too many packs in the repository. If the number of loose objects exceeds the value of the gc.auto configuration variable, then all loose objects are combined into a single pack using git repack -d -l. Setting the value of gc.auto to 0 disables automatic packing of loose objects.

If the number of packs exceeds the value of gc.autopacklimit, then existing packs (except those marked with a .keep file) are consolidated into a single pack by using the -A option of git repack. Setting gc.autopacklimit to 0 disables automatic consolidation of packs.

And in the end:

The git gc --auto command will run the pre-auto-gc hook. See githooks(5) for more information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!