Last Updated: July 24, 2020
· jussi-kalliokoski

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 !

4 Responses
Add your response

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.

over 1 year ago ·

@mlafeldt very nice! It also makes it branch-agnostic! Thanks!

over 1 year ago ·
over 1 year ago ·

@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.

over 1 year ago ·