git - git filter-branch 的正确并行化

标签 git git-filter-branch git-rewrite-history

我有一个包含大量分支的存储库,并且“git filter-branch ... -- --all”逐渐减慢速度(大约 400,000 次提交,大约运行时间 7 天)。但是单个分支上的“git filter-branch”可以显着提高性能(大约 5 天)。

使用以下算法在分支负载上并行化“过滤器分支”是否正确?

  1. 对于 bx (B1..Bn) 执行:git clone --bare -b bx repo.orig repo.bx
  2. 在 repo.bx 上并行化:git filter-branch --index-filter ... -- HEAD
  3. git init --bare repo.new
  4. 对于 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/

相关文章:

node.js - 从所有 git 历史记录中删除文件

git - 如何从 Git 的历史记录中永久删除提交?

linux - 如何使用 ssh 创建存储库 ://access on a server

Git 无法识别文件的重命名

git - 在 git 中提取一个已重命名的子目录历史记录

git - 重写历史 git filter-branch create/split into submodules/subprojects

Git bash(薄荷糖)。怎么打开最大化

git - 将 git 更改 pull 入尚未 checkout 的分支

git - 从 Git 存储库中拆分子目录并保留子目录中所有文件的历史_now_

git-filter-branch 删除字符串,但其中字符串包含 $ '\和其他字符