git mv文件根据正则替换
我正在尝试重命名大量错误命名的文件,这些文件已在我的本地GIT存储库中跟踪。这些文件当前是foo.txt_1.txt
的形式。我想将它们更改为foo.txt
。
这就是我到目前为止一直在尝试的事情:
ls *_1.txt | xargs -I {} git mv -n {} newfilename
如果newfileName
我想要替换,我不确定应该使用什么。
I am trying to rename a large number of incorrectly named files, which are tracked in my local git repo. The files are currently of the form foo.txt_1.txt
. And I want to change them to foo.txt
.
This is what I have been experimenting with so far:
ls *_1.txt | xargs -I {} git mv -n {} newfilename
I'm just not sure what I should use in place if newfilename
to make the substitution I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
围绕它的循环更容易。
这将呼应它将运行的命令,以便您可以检查其正确。从“ git”命令之前从“ git”命令中删除“ echo”以实际执行。
bash inline替换工作类似:
其中
var
是变量名称,而要删除的模式位于/
s之间。这只是文本,但是您可以在此处使用正则表达式。This is easier with a for loop around it.
This will echo the commands it would run so you can check it's correct. Remove "echo" from before the "git" command to actually execute.
Bash inline substitution works like this:
Where
VAR
is the variable name, and the pattern to remove is between the/
s. Here it's simply text, but you can use regular expressions here.