Is there a 'git sed' or equivalent?
You could use git ls-files
in combination with xargs
and sed
:
git ls-files -z | xargs -0 sed -i -e 's/old-method-name/new-method-name/g'
Thanks to both Noufal and Greg for their posts. I combined their solutions, and found one that uses git grep (more robust than git ls-files for my repo, as it seems to list only the files that have actual src code in them - not submodule folders for example), and also has the old method name and new method name in only one place:
In the [alias]
block of my ~/.gitconfig
file:
sed = ! git grep -z --full-name -l '.' | xargs -0 sed -i -e
To use:
git sed 's/old-method-name/new-method-name/ig'
You could do a
for i in $(git grep --full-name -l old_method_name)
do
perl -p -i -e 's/old_method_name/new_method_name/g' $i
done
stick that in a file somewhere and then alias it as git sed
in your config.
Update: The comment by tchrist below is a much better solution since it prevents perl from spawning repeatedly.