Git:一次重命名或移动所有文件

Jun*_*Ito 15 git

我想将我的Git项目中的所有erb文件重命名为haml.(比如index.html.erb到index.html.haml)

如果我重命名每个文件,我必须输入以下命令超过三十次.

$ git mv app/views/pages/index.html.erb app/views/pages/index.html.haml
Run Code Online (Sandbox Code Playgroud)

我尝试了下面的命令,但它没有用.

$ 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
Run Code Online (Sandbox Code Playgroud)

我怎样才能立刻重命名它们?

Bor*_*lid 28

for i in $(find . -iname "*.erb"); do
    git mv "$i" "$(echo $i | rev | cut -d '.' -f 2- | rev).haml";
done
Run Code Online (Sandbox Code Playgroud)

对于每个.erb文件,git mv它自身的扩展名为".erb",替换为".haml".


chr*_*389 9

使用 powershell 的单内衬

Dir *.erb -Recurse | foreach { git mv $_.FullName $_.FullName.replace("erb", "haml")}
Run Code Online (Sandbox Code Playgroud)

  • 这有效,但也会替换整个路径中的所有“erb”实例,而不仅仅是扩展名。我使用的是:`Dir *.h -Recurse | foreach { git mv $_.FullName ($_.Directory.FullName + "\" + $_.BaseName + ".hpp") }`。 (2认同)