现在合并一些文件,以后再合并 [英] Merge some files now and some later

查看:86
本文介绍了现在合并一些文件,以后再合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在分支B中.一堆提交后,分支A准备/需要一些文件,但许多文件尚未准备/需要.我只想合并这些文件,并保留正确的git历史记录.后来,当我真正合并时,我不希望对这些更改的起源有任何误导性的线索-即使这些提交中包含的其他文件中的更改未合并,它们也应该正确地引用它们来自的提交(至今).我想这意味着将提交分成可以与不关心这些文件的部分.

I am in branch B. After a bunch of commits, a few files are ready/needed by branch A, but many aren't ready/needed. I want to merge just those files, keeping proper git history. Later, when I really merge, I don't want any misleading trail about the origin of these changes -- they should properly reference the commits they came from, even though changes in other files that were part of those commits were not merged (yet). I guess that means dividing commits into pieces that do vs. don't concern these files.

为此提出的所有解决方案最终都失去了这些更改的历史,并在我以后想要将B合并到A但B的某些更改已经存在时引起了一个大问题.我想要一个避免这种情况的解决方案.

All proposed solutions for this wind up losing the history of these changes and cause a big problem when I later want to merge B into A but some of B's changes are already there. I want a solution that avoids this.

在乌龟中,我可以查看单个文件的日志,然后选择一些较旧的版本进行还原.因此,原则上,我可以从B创建一个新的分支C,然后将所有我不想合并的文件还原到B从A分支到该点的位置.然后,我可以合并C到A.这似乎可以正确跟踪git的历史记录,并让我将B合并到A中,而不会为B已有一些更改感到惊讶.

In tortoise, I can look at the log for a single file and choose some older revision to revert to. So, in principle, I could make a new branch C, from B, and revert all the files I don't want to merge back to the point when B branched from A. Then I could merge C to A. That seems to properly track git history and lets me merge B into A without being surprised that some B changes are already there.

但是,当我只想合并2时,手动识别并还原20个文件会很痛苦.为什么这不是常见的一步操作?乌龟的还原工作原理-由于它可以对单个文件进行操作,因此必须进行子提交,这是我正在寻找的基本功能.

But it's painful to manually identify and revert 20 files, when I just want to merge 2. Why isn't this a common one-step operation? How does tortoise's revert work -- since it can operate on a single file, it must be sub-commit, which is the essential feature I'm looking for. Is it throwing away the fact that I am going from a newer revision to an older one, and making it look like I just made some manual changes that will then conflict with the eventual merge of B back to A?

推荐答案

您正在寻找

You are looking for cherry pick, a method to pick only certain commits from a branch to be merged.

要仅合并某些文件(当您不想合并整个提交时),确实有多种解决方案,我喜欢使用

To merge only certain files (when you don't want to merge a whole commit), you have multiple solutions indeed, i like to use the one well-expressed in this article, it's a pain in the arse anyway, bit it's the simpler i found to to that kind of things.

您还可以拆分一些提交并仅合并那些包含正确文件的提交,您可以像其他文章说

You can also split some commits and merge only the ones that contains the right files, and you can do like that other article says

这篇关于现在合并一些文件,以后再合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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