问题描述
我想为Git存储库中的所有提交重命名文件.这是我尝试过的:
I want to rename a file for all the commits in Git repository. Here's what I have tried:
git filter-branch --index-filter 'git mv -k <old name> <new name>' HEAD
此命令遍历了存储库中的所有提交,但最终显示了以下消息:
This command went through all the commits in the repository, but it ended up with the message:
这意味着什么都没有改变.这里出了什么问题?
which means nothing had been changed. What had been wrong here?
请注意,我要重命名的文件从第一次提交起就不存在.因此,如果我没有在 git mv
中使用 -k
,我的意思是如果我使用:
Note that the file which I wanted to rename doesn't exist from the first commit. Therefore if I do not use -k
in git mv
, I mean if I use:
git filter-branch --index-filter 'git mv <old name> <new name>' HEAD`
在尝试进行第一次提交时,如错误的来源..."之类的东西,Git会出错.
Git would error out while trying the first commit saying something like "bad source...".
推荐答案
我终于使用以下方法解决了原来的问题:
I finally solved my original problem by using:
git filter-branch --tree-filter '
if [ -f <old name> ]; then
mv <old name> <new name>
fi' --force HEAD
这篇关于重命名Git存储库中所有提交的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!