我有一个包含大量分支的存储库,并且“git filter-branch ... -- --all”逐渐减慢速度(大约 400,000 次提交,大约运行时间 7 天)。但是单个分支上的“git filter-branch”可以显着提高性能(大约 5 天)。
使用以下算法在分支负载上并行化“过滤器分支”是否正确?
- 对于 bx (B1..Bn) 执行:git clone --bare -b bx repo.orig repo.bx
- 在 repo.bx 上并行化:git filter-branch --index-filter ... -- HEAD
- git init --bare repo.new
- 对于 bx (B1..Bn) 执行:cd repo.bx; git push repo.new HEAD:bx
此致,格特
最佳答案
恭喜您找到了一种有趣的方法来并行执行 git filter-branch
- 我认为原则上,您所描述的过程将成功给出正确的结果& 内部一致的重写历史记录,尽管这肯定取决于您的 --index-filter
命令正在执行的操作(如果例如,您正在做一些疯狂的事情,例如将随机数插入文件中)。
git filter-branch
是一个非常强大的工具:它允许您对每个文件执行完全任意的操作并在您的历史中提交 - 尽管这种灵活性听起来很有吸引力,但它常常对您不利 - 您为此付出了执行时间沉重的代价。所以问题是——你需要这种灵活性吗?您能否更具体地说明您想要实现的目标?
The BFG ,git filter-branch 的替代品...
从 Git v1.9 开始,documentation notes for git filter-branch
包含这个建议(诚然是我自己贡献的,但经过了 Git 邮件列表的审查!):
git-filter-branch allows you to make complex shell-scripted rewrites of your Git history, but you probably don't need this flexibility if you're simply removing unwanted data like large files or passwords. For those operations you may want to consider The BFG Repo-Cleaner, a JVM-based alternative to git-filter-branch, typically at least 10-50x faster for those use-cases, and with quite different characteristics
BFG 可以执行 git filter-branch
所执行的许多任务 - 但速度快得多 - 部分原因是它使用记忆化,但也因为它执行清理任务的并行化,使其能够充分利用多核机器。这些因素结合在一起,可以节省执行时间,而不是通过并行过滤器分支运行可能减少 30% 的时间 - 事实上,运行时间减少通常更接近 98% ,50 倍 加速或以上。
A comment by Elliot Glaysher ,负责 Google Chrome 的 Google 工程师:
I was able to shrink the current repository down to ~500 megabytes in about 10 minutes when using this tool. My hand crafted scripts clock in at 615 megabytes in 3 days time for comparison.
总而言之,值得考虑的是 BFG 是否可以成为完成这项工作的更好工具。
全面披露:我是 BFG Repo-Cleaner 的作者。
关于git - git filter-branch 的正确并行化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21850139/