git cherry-pick,目标文件已重命名 [英] git cherry-pick with target file renamed

查看:140
本文介绍了git cherry-pick,目标文件已重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个分支用于不同版本-一个分支用于当前开发,另一个分支具有多年的长期支持.结果,它们之间存在显着差异.我在两个分支中都存在一些文件,但是在开发中已将其重命名.修复程序最初是在开发分支中进行的,但后来发现在支持分支中也是必需的.但是Cherry-pick报告说该文件在support分支中不存在(因为它在开发中已重命名,并且在support中它具有不同的名称).

I have two branches for different versions - one for current development and another is long-time support several years old. As a consequence they differ significantly. I have some file that exists in both branches, but was renamed in development. One of fixes was made in development branch originally, but later found to be required in support branch as well. But cherry-pick reports that the file does not exist in support branch (because it was renamed in development and in support it has different name).

这个特定文件的内容是相似的,因此似乎应该很好地应用补丁-如果我可以将它定向到git哪个文件.有没有办法(最好是在命令行中)手动指导git做我需要的事?

Contents of this particular file is similar, so it seems patch should be applied fine - if I can direct git what file it should apply it to. Is there a way (preferably in command line) to manually direct git to do what I need?

推荐答案

cherry-pick命令正在使用相同的合并策略作为合并命令.默认的 recursive 合并策略在正常情况下能够检测到重命名,但是如果文件之间的差异太大(在这种情况下),它将失败.

The cherry-pick command is using the same merge strategies as the merge command. The default recursive merge strategy is able to detect renames under normal circumstances, but it can fail if the files have diverged too much like in this case.

除了其他答案中概述的低级索引黑客攻击外,还可以通过摆弄策略选项来使其简单工作,例如,提高将相似文件视为重命名版本的阈值(默认为50%):

Apart from the low level index hacking outlined in the other answer, it might be possible to make it work simply by fiddling with the strategy options, for example increase the threshold for considering a similar file to be a renamed version (default is 50%):

git cherry-pick -Xrename-threshold=20% 0123sourcecommithash


否则,您也可以始终以手动方式进行操作,即


Otherwise you could also always do it the manual way, i.e.

git format-patch 0123sourcecommithash -1

然后编辑创建的0001-Commit-message-here.patch来更改文件路径,然后再次应用于目标分支:

Then edit the created 0001-Commit-message-here.patch to change the file path and apply again on the target branch:

git am 0001-Commit-message-here.patch

它将保留所有原始提交消息,作者姓名,日期等,并且可以作为一种简单的解决方案.

It will retain all original commit messages, author names, dates etc. and might work as an easy one shot solution.

这篇关于git cherry-pick,目标文件已重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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