I've cloned a git
repo and I need to start a new project based off of it.
How do I rename it, making sure everything is taken care of?
I'm using macOS.
I've cloned a git
repo and I need to start a new project based off of it.
How do I rename it, making sure everything is taken care of?
I'm using macOS.
Based off of nerdyworm's rename.sh, that uses ack
I've adapted it to use git grep
and run on macOS easily.
• OTP NAME: Snake Case (snake_case) name for the Application.
• NAME: Regular app name.
$ git grep -l $CURRENT_OTP | xargs sed -i '' -e "s/$CURRENT_OTP/$NEW_OTP/g"
$ git grep -l $CURRENT_NAME | xargs sed -i '' -e "s/$CURRENT_NAME/$NEW_NAME/g"
$ mv lib/$CURRENT_OTP lib/$NEW_OTP
$ mv lib/$CURRENT_OTP.ex lib/$NEW_OTP.ex
I do not know of any way to do this automatically with perfect accuracy, but these are the steps I follow manually when I need to rename Phoenix projects.
The commands below assume your code is in a git
repo and the old application is my_app
/ MyApp
and the new one is my_new_app
/ MyNewApp
. The process is brittle -- if your application or module name can occur in many places (e.g. it's a single letter A
or something), then this will not work.
# search replace both the application name and module name in all files indexed by git
$ git ls-files -z | xargs -0 perl -p -i -e 's/my_app/my_new_app/g; s/MyApp/MyNewApp/g;'
# rename `lib/my_app`
$ mv lib/my_app lib/my_new_app
After that I run mix test
and fix any compilation errors or test failures.
Finally I do a quick review of git diff
to make sure everything looks right.