Git apply a change to all files in all previous commits

Viewed 204

I would like to apply a change to all my files in my git history. 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.
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).
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. I tried to do something similar with git rebase but I get the same error.
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 ? Thanks in advance.

1 Answers

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'
Related