将相同的文件重命名更改应用于不同的 GIT 分支

发布于 2024-09-28 07:44:37 字数 421 浏览 0 评论 0原文

我有一个项目,有一个主分支和一个稳定分支 - 分支很久以前就分叉了。现在我在稳定分支上有一些提交,我也想在主分支上有这些提交(错误修复)。我无法合并,因为分支分歧并且有大量未合并的更改 - 我只想要 4 次提交。

所以我尝试了樱桃采摘。但是,由于顶级模块名称从“项目模块”方案更改为“模块”,因此这会失败。当挑选时,GIT 在旧目录中创建新文件(如在旧分支上):未检测到重命名。这可能是因为我收到此警告:

warning: too many files (created: 278 deleted: 5364), skipping inexact rename detection

我尝试了 git format-patch + git am,但这再次在旧目录中创建文件。

如何将提交应用到主分支?

谢谢, 亚当

I've got a project which has a master branch and a stable branch - the branches diverged long time ago. Now I've got a couple commits on the stable branch, which I also want to have on the master branch (a bug fix). I cannot merge, as the branches diverged and there's loads of unmerged changes - I just want the 4 commits.

So I tried cherry-pick. However this fails since the top-level modules names changed from "project-module" scheme to "module". When cherry-picking, GIT creates the new files in the old directories (as on the old branch): the rename isn't detected. That's possibly because I get this warning:

warning: too many files (created: 278 deleted: 5364), skipping inexact rename detection

I tried git format-patch + git am, but this again creates the files in the old directories.

How can I apply the commits to the master branch?

Thanks,
Adam

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聚集的泪 2024-10-05 07:44:37

我怀疑您可以通过更改 merge.renameLimit 的值来使其工作(但需要很长时间):

merge.renameLimit

合并期间执行重命名检测时要考虑的文件数量;如果未指定,则默认为 diff.renameLimit 的值。

我相当肯定,cherry-pick 也会尊重这个价值。如果没有,您可以找到两个分支的共同祖先,在那里应用提交,然后将它们合并到两个分支中,以确保它使用合并机制。 (请注意,这实际上是我首先建议做的事情。合并比樱桃选择更可取,因为它们不会创建重复的提交,并且保留历史记录流。)

I suspect you could make it work (but take a long time) by changing the value of merge.renameLimit:

merge.renameLimit

The number of files to consider when performing rename detection during a merge; if not specified, defaults to the value of diff.renameLimit.

I'm fairly certain cherry-pick will respect that value as well. If it doesn't, you could find a common ancestor of the two branches, apply the commits there, and then merge them into both branches, to make sure it's using the merge machinery. (Note that this is actually what I'd recommend doing in the first place. Merges are very much preferable to cherry-picks, because they don't create duplicate commits, and they preserve the flow of history.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文