重命名Git存储库中所有提交的文件 [英] Rename file for all commits in a Git repository

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

问题描述

我想为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:

警告:Ref'refs/heads/master'不变

WARNING: Ref 'refs/heads/master' is unchanged

这意味着什么都没有改变.这里出了什么问题?

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存储库中所有提交的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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