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

6
我希望使用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

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

上述方法将影响测试仓库的所有3个提交。例如,有没有一种方法只影响最后2个提交呢?

对于我的用例,blob操作应该完美地工作,因为我只想处理我的提交修改过的blob。

我在文档中没有轻松找到相关信息

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

已经在git-filter-repo ac039ecc095d上进行了测试。


使用交互式变基? - dan1st
1个回答

7
尝试在您的--refs参数中指定一个提交范围:
git filter-repo ... --refs HEAD~2..master

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接