为git仓库中的所有提交重命名文件 [英] Rename file for all commits in git repository
问题描述
我想为git仓库中的所有提交重命名文件,这里是我
已经尝试过的内容:
git filter-branch --index-filter'git mv -k<旧名称> <新名称> HEAD
这个命令通过在储存库中的所有提交去,但最终用
信息
警告:Ref'refs / heads / master'不变
blockquote>
这意味着什么都没有改变。这里有什么问题?请注意,我想重命名的文件在第一次提交时不存在,因此如果我不使用
, code> -k 在git mv
中,我的意思是如果我使用:git filter-branch --index-filter'git mv< old name> < new name>'HEAD`
Git会在尝试第一次提交时出错,
source ...。解决方案我终于用下面的方法解决了我原来的问题: b
$ b'预类= 郎的bash prettyprint-越权>git的滤波器分支--tree滤波器'
如果[-f<旧名称> ]。然后
mv<旧名称> <新名称>
fi'--force HEAD
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 ended up with the message
WARNING: Ref 'refs/heads/master' is unchanged
which means nothing had been changed. What had been wrong here?
Note that the file which I wanted to rename doesn't exist from the first commit, therefore if I do not use
-k
ingit mv
, I mean if I use:git filter-branch --index-filter 'git mv <old name> <new name>' HEAD`
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仓库中的所有提交重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!