Skip to content

Instantly share code, notes, and snippets.

@DavidYKay
Created September 7, 2012 16:20
Show Gist options
  • Save DavidYKay/3667517 to your computer and use it in GitHub Desktop.
Save DavidYKay/3667517 to your computer and use it in GitHub Desktop.
Git search and replace
#!/bin/bash
#~/.scripts/git-sub
#Author: Khaja Minhajuddin <minhajuddin@cosmicvent.com>
#script which does a global search and replace in the git repository
#it takes two arguments
#e.g. git sub OLD NEW
old=$1
new=$2
for file in $(git grep $old | cut -d':' -f 1 | uniq)
do
echo "replacing '$old' with '$new' in '$file'"
sed -i -e "s/$old/$new/g" $file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment