简体   繁体   English

Git 将更改应用于所有先前提交中的所有文件

[英]Git apply a change to all files in all previous commits

I would like to apply a change to all my files in my git history.我想对我的 git 历史记录中的所有文件应用更改。 More precisely, I would like to modify a specific line which is the author name (it is written in the header of all my files, I am not talking about the git author) to remove the previous value from all the git history and change it by the new one.更准确地说,我想修改一个特定的行,即作者姓名(它写在我所有文件的 header 中,我不是在谈论 git 作者)从所有 ZBA9F11ECC3492BD61E5Z 历史记录中删除以前的值并更改它由新的。
So far, I have tried to use git filter-branch to perform the following command: sed -i -e "s/<previous_author>/<new_author>/" which works perfectly when I try it on a single file (<previous_author> is indeed replaced by <new_author> in the file).到目前为止,我已经尝试使用git filter-branch来执行以下命令: sed -i -e "s/<previous_author>/<new_author>/"当我在单个文件(<previous_author>确实被文件中的 <new_author> 替换)。
However, when I use git filter-branch -f --tree-filter 'sed -i -e "s/<previous_author>/<new_author>/"' HEAD I get an error sed: -i may not be used with stdin .但是,当我使用git filter-branch -f --tree-filter 'sed -i -e "s/<previous_author>/<new_author>/"' HEAD时,我收到错误sed: -i may not be used with stdin . I tried to do something similar with git rebase but I get the same error.我试图用git rebase做类似的事情,但我得到了同样的错误。
So is there a way to do this, so to exec sed -i -e "s/<previous_author>/<new_author>/" on all files of all my previous commits?那么有没有办法做到这一点,所以要对我之前提交的所有文件执行sed -i -e "s/<previous_author>/<new_author>/" Thanks in advance.提前致谢。

You can try something like你可以尝试类似的东西

git filter-branch -f --tree-filter \
'if git grep --name-only "@author";  
 then
    git grep --name-only "@author" | xargs sed -i -e "s/@prev_auth/@new_author/"
 fi'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM