How to modify only a range of commits with git filter-repo instead of the entire branch history?

被刻印的时光 ゝ 提交于 2021-01-29 05:15:42

问题


I want to use git filter-repo to automatically apply some scripted style-guide refactoring for my multi-commit pull requests.

Therefore I want to apply the operations only to the few latest new commits I'm pushing, but not touch anything else in older history.

Is there a way?

For the sake of concreteness, here's a test repo : https://github.com/cirosantilli/test-git-filter-repository and a sample blob operation:

# 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

based on: How to replace a string in a whole Git history?

The above would affect all 3 commits of the test repo. Is there a way to affect only the last 2 commits instead for example?

A blob operation should work perfectly for my use case, as I only want to touch blobs that my commits modified.

I couldn't find it easily in the documentation.

I also asked on their issue tracker: https://github.com/newren/git-filter-repo/issues/157

Tested on git-filter-repo ac039ecc095d.


回答1:


Try specifying a commit range as your --refs argument :

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

I haven't found a mention is the docs either, but from the code, it looks like it is passed straight to git fast-export.



来源:https://stackoverflow.com/questions/64154624/how-to-modify-only-a-range-of-commits-with-git-filter-repo-instead-of-the-entire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!