Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a 'git sed' or equivalent?

Tags:

git

linux

bash

sed

Let's say I want to rename a method in source code contained in a git repository. I could do this by hand, but the method name might be in multiple places (e.g., unit test, documentation, actual method). To check where the method is used, I use 'git grep'. I get 'git grep' to show only lines that I want to change, and then I don't have a workflow to automatically change those lines.

I'm looking for an automated way (hopefully using git tools) to do this last step. I was hoping there was some sort of 'git sed' or equivalent, but I can't find any.

The interface I'm thinking would be nice: git sed 's/old-method-name/new-method-name/g'

like image 962
Clayton Stanley Avatar asked Mar 11 '12 02:03

Clayton Stanley


1 Answers

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' 
like image 161
Greg Hewgill Avatar answered Sep 20 '22 21:09

Greg Hewgill