为git仓库中的所有提交重命名文件 [英] Rename file for all commits in git repository

查看:137
本文介绍了为git仓库中的所有提交重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为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 in git 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆