Replace all occurences of 'Shard' with 'Card' in the git repo
This comes often handy for me for example if I want to rename a class name and apply it everywhere:
$ sed -i 's/Shard/Card/g' $(git ls-files)
Simply put, the part in the parenthesis extracts all filenames under source control for the current repo. Those get applied as target files for an in-place sed
replacement.
To make sure that there are no Shards left:
$ git grep 'Shard'
EDIT: It should be noted that it's a good idea to test that you broke nothing, as well as verifying that you did not change anything appropriate (check the diff).
EDIT 2: Shorter and branch-agnostic, à la @mlafeldt !
Written by Jussi Kalliokoski
Related protips
4 Responses
this looks great. I can't wait to try it out. I often use
sed -i 's#string#otherstring#g' filename
for a replace in a single file.
thanks for the great tip bro.
@mlafeldt very nice! It also makes it branch-agnostic! Thanks!
How about using gsr? See: https://github.com/da-x/git-search-replace
@da-x: seems great! I wonder if you could also add support for interactive mode in the vein of git add -p
and friends. Maybe you could even (ab)use git itself for the UI.