使用 Git 强制远程存储库压缩 (GC)

发布于 2024-10-03 18:55:14 字数 239 浏览 5 评论 0原文

我正在使用 Git 来对一系列二进制文件进行版本控制。它们压缩得很好,但是当我推送它们时,我的中央存储库似乎没有压缩。它们占用了我相当多的配额,所以我想看看是否有办法强制远程存储库执行 GC。

这可能吗?我正在开发 Project Locker,所以我不相信我有 SSH 访问权限来进入并 GC 存储库我。有什么想法吗?谢谢。

I'm using Git to version a series of binary files. They compress pretty well, but my central repos do not seem to be compressing when I push to them. They're eating up a decent amount of my quota, so I was looking to see if there was a way to force the remote repo to do a GC.

Is this possible? I'm working on Project Locker so I don't believe I have SSH access to go in and GC the repo myself. Any ideas? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

番薯 2024-10-10 18:55:14

如果您自己无法运行 git gc,则必须欺骗它自动运行。那时您将无法完全控制它,但您至少应该能够让它运行。

git gc --auto 由多个命令运行;这里相关的是 receive-pack,它在远程运行以接收包作为推送的一部分。 gc --auto 仅当有足够的松散对象时才重新打包;截止值由配置参数 gc.auto 确定,默认为 6700。

如果您有权访问远程的 gitconfig,则可以将该截止值暂时设置为 1。存储库中肯定至少有 1 个松散对象,因此这应该会导致 gc --auto 在您下次推送时执行其操作。

如果你无法访问远程的 gitconfig,我能想到的就是人为地创建一堆松散的对象。您可以通过创建一个分支,向其提交一堆小文件(具有不同内容),将分支推送到远程,然后从远程删除分支来做到这一点。 (重要的是要改变内容,否则他们只会使用相同的斑点。)冲洗并重复。

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.

情定在深秋 2024-10-10 18:55:14

这确实是他们需要解决的问题。他们可以使用 post-receive hook 或 cron job 或类似的东西来完成此操作,但如果他们应该维护您的存储库,那么出于多种原因,这也是其中的一部分。

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.

燕归巢 2024-10-10 18:55:14

表单 git-gc man页面

某些 git 命令可能会自动运行 git gc;有关详细信息,请参阅下面的 --auto 标志。

更进一步:

--自动

使用此选项,git gc 检查是否需要任何内务处理;如果不是,则退出而不执行任何工作。某些 git 命令在执行可能创建许多松散对象的操作后运行 git gc --auto。

如果存储库中有太多松散对象或太多包,则需要进行内务管理。如果松散对象的数量超过 gc.auto 配置变量的值,则使用 git repack -d -l 将所有松散对象组合成一个包。将 gc.auto 的值设置为 0 将禁用松散对象的自动打包。

如果包的数量超过 gc.autopacklimit 的值,则使用 git repack 的 -A 选项将现有包(标有 .keep 文件的包除外)合并为单个包。将 gc.autopacklimit 设置为 0 会禁用包的自动合并。

最后:

git gc --auto 命令将运行 pre-auto-gc 挂钩。请参阅 githooks(5) 了解更多信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文