Git Grep and Replace

Git Grep and Replace

Logo
The Bytestack TeamPublished 2024-07-01

Git Grep and Replace

If you want to replace a string in a bunch of files, you can use the following command:

On Linux:

git grep -l 'original_text' | xargs sed -i 's/original_text/new_text/g'

On Mac/OSX:

git grep -l 'original_text' | xargs sed -i '' -e 's/original_text/new_text/g'

Explanation

-l limits the output to the names of the files that contain the string -e tells sed to use extended regular expressions (needed for osx)

Ready to dive in?Start your free trial today.

Experience the power of Bystack for your team.