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

问题描述

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

因此,我只想将这些操作应用到我要推送的一些最新的新提交中,而不要触及较旧的历史记录中的其他任何内容

有办法吗?

为具体起见,这是一个测试仓库:example一个示例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

基于:https://github.com/cirosantilli/test-git-filter-repository

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

对于我的用例来说,blob操作应该可以完美地工作,因为我只想触摸提交已修改的blob。

How to replace a string in a whole Git history?我很难找到它。

我还询问了他们的问题跟踪器:in the documentation

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

解决方法

尝试将提交范围指定为--refs参数:

git filter-repo ... --refs HEAD~2..master

我也没有提到文档,但是from the code似乎直接传递给git fast-export