git packs: 创建选择性和优化的“受保护”包?

huangapple go评论66阅读模式
英文:

git packs: creation selective "protected" and optimised pack?

问题

$dayjob的主要仓库相当庞大,同时拥有相对稳定的“仅更新”分支和相当积极地更新和重写的开发和集成分支。

git gc --aggressive(或者通过 --repack 进一步提高的更激进策略)可以很好地工作,并且可以显著改善仓库的大小,但它们会重新打包整个仓库,这意味着它们会将开发分支中的大量即将成为垃圾的内容与稳定分支一起打包。

是否有一种简单的方法可以让git提供一个“稳定”分支列表,它应该将它们打包在一起,并且只在显式标记打包为替换或类似操作时才进行增量更新?

英文:

$dayjob's main repository is pretty big, and has both relatively stable "update-only" branches and fairly aggressively updated and rewritten development and integration branches.

git gc --aggressive (or an even more aggressive strategy via --repack) work well and can significantly improve the size of the repository, however they repack the entire repository meaning they pack a bunch of soon-to-be garbage from dev branches alongside the stable ones.

Is there an easy way to give git a list of "stable" branches it should pack together, and possibly only incrementally update unless the pack is explicitly marked for replacement or something along those lines?

答案1

得分: 1

Git的标准GC行为没有任何控制打包的选项。默认情况下,它会将未打包的对象打包成一个包,并且如果包太多(默认为50),会将对象重新打包成一个大包。

如果您想创建一个特定的优化包,并且无论如何都要保留它,可以像这样操作:

tmpdir=$(mktemp -d)
# 调整以打印您想要的任何引用。
echo refs/heads/master | git pack-objects --revs --progress $tmpdir/pack
touch "$tmpdir/$(basename "$tmpdir/"*.pack .pack).keep"
mv "$tmpdir/"* .git/objects/pack/
rm -fr "$tmpdir"

这将把所有引用(在我的示例中是master)打包到一个包中,并用.keep文件标记它以便保留。如果有足够的散装对象,其他对象仍然会被打包。

当您想重新打包存储库时,删除现有的.keep文件,然后再次运行这些命令。

如果您想要更积极地打包,可以向git pack-objects传递额外的参数来实现这样的打包。

如果您使用标准的托管解决方案,那么服务器端应该会在合理的间隔上自动在服务器上进行打包。

英文:

Git's standard GC behavior doesn't have any options to control what gets packed together like that. It will by default pack unpacked objects into a pack, and repack objects into a large pack if there are too many packs (by default, 50).

If you want to create a specific pack that's optimized and that you want to keep no matter what, you can do something like this:

tmpdir=$(mktemp -d)
# Adjust to print whatever refs you want.
echo refs/heads/master | git pack-objects --revs --progress $tmpdir/pack
touch "$tmpdir/$(basename "$tmpdir/"*.pack .pack).keep"
mv "$tmpdir/"* .git/objects/pack/
rm -fr "$tmpdir"

That will pack all of the refs (in my example, master) into one pack and mark it to be kept with a .keep file. Other objects will still be packed if there are enough loose objects.

When you want to repack the repository, delete the existing .keep file, and run those commands again.

If you want a more aggressive packing, you can pass additional arguments to git pack-objects that will produce such a packing.

If you use a standard hosting solution, then the server side should take care of automatically packing on the server at a reasonable interval.

huangapple
  • 本文由 发表于 2020年1月6日 16:05:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608612.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定