I want to rename all erb files in my Git project to haml.(like index.html.erb to index.html.haml)
If I rename each file, I have to type the following command more than thirty times.
$ git mv app/views/pages/index.html.erb app/views/pages/index.html.haml
I tried the command below, but it did not work.
$ git mv app/views/**/*.erb app/views/**/*.haml
usage: git mv [options] <source>... <destination>
-n, --dry-run dry run
-f, --force force move/rename even if target exists
-k skip move/rename errors
How can I rename them at once?
In your repository, browse to the file you want to rename. In the upper right corner of the file view, click to open the file editor. In the filename field, change the name of the file to the new filename you want. You can also update the contents of your file at the same time.
We use the git mv command in git to rename and move files. We only use the command for convenience. It does not rename or move the actual file, but rather deletes the existing file and creates a new file with a new name or in another folder.
Git keeps track of changes to files in the working directory of a repository by their name. When you move or rename a file, Git doesn't see that a file was moved; it sees that there's a file with a new filename, and the file with the old filename was deleted (even if the contents remain the same).
for i in $(find . -iname "*.erb"); do
git mv "$i" "$(echo $i | rev | cut -d '.' -f 2- | rev).haml";
done
For each .erb file, git mv
it to itself with the extension ".erb" replaced by ".haml".
A one liner using powershell
Dir *.erb -Recurse | foreach { git mv $_.FullName $_.FullName.replace("erb", "haml")}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With