0aolpg
Last Updated: February 25, 2016
·
3.625K
· 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 !

5 Responses
Add your response

4545

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 ·
4552

Psst. You might want to replace this

git ls-tree -r master | awk "{print \$4}"

with this:

git ls-files

:)

over 1 year ago ·
4553

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

over 1 year ago ·
19316
over 1 year ago ·
19508

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