如何使用 git filter-repo 仅修改一系列提交而不是整个分支历史记录?

Cir*_*四事件 6 git git-filter-repo

我想git filter-repo为我的多提交拉取请求自动应用一些脚本化样式指南重构。

因此,我只想将这些操作应用于我正在推送的几个最新的新提交,而不是触及旧历史中的任何其他内容。

有办法吗?

为了具体起见,这里有一个测试存储库:https://github.com/cirosantilli/test-git-filter-repository和一个示例 blob 操作:

# Install git filter-repo.
# https://superuser.com/questions/1563034/how-do-you-install-git-filter-repo/1589985#1589985
python3 -m pip install --user git-filter-repo

# Usage.
git clone https://github.com/cirosantilli/test-git-filter-repository
cd test-git-filter-repository
printf 'd1==>asdf
d2==>qwer
' > replace.txt
git filter-repo --replace-text replace.txt --refs HEAD
Run Code Online (Sandbox Code Playgroud)

基于:如何替换整个 Git 历史记录中的字符串?

上述内容将影响测试存储库的所有 3 次提交。例如,有没有办法只影响最后两次提交?

Blob 操作应该非常适合我的用例,因为我只想触及我的提交修改的 Blob。

我在文档中找不到它。

我还询问了他们的问题跟踪器:https://github.com/newren/git-filter-repo/issues/157

在 git-filter-repo ac039ecc095d 上测试。

LeG*_*GEC 7

尝试指定提交范围作为您的--refs参数:

git filter-repo ... --refs HEAD~2..master
Run Code Online (Sandbox Code Playgroud)

在文档(链接)中,我没有找到明确的声明说提交范围是 的有效值--refs <refs+>,但代码说它直接传递到git fast-export,所以它们在实践中。