使用git同时维护不同版本的代码 [英] maintain different versions of the code simultaneously using git

查看:430
本文介绍了使用git同时维护不同版本的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要优化的代码。我想同时维护一组代码版本(每个版本可以描述为一些功能,优化的组合)。最终,我将决定哪个版本是最佳版本。我不想将这些版本合并为更少的版本。但是,我希望能够对(大)源文件进行(较小)修改,该修改可能会在各个版本之间转移,并且我希望此修改能够写入多个(可能是所有)版本。

I got a code that I'm required to optimize. I would like to maintain a set of versions of the code (each version can be described as a composition of some features, optimizations) simultaneously. Eventually, I'll decide which version is the best one. I do not want to merge these versions into fewer versions. However, I would like to be able to make a (minor) modification to a (big) source file which may divert across the versions and I want this modification to write through more than one (possibly all) versions. How can I achieve that with git?

例如,让我们考虑3个版本: v1 v2 v3 和源代码文件 source.cpp ,其中许多代码在所有版本中都不同,但类A方法 aMethod()是相同的。我想更新该方法并将更新仅写入版本 v1 v2

For example let us consider 3 versions: v1, v2, v3 and source code file source.cpp which has lots of code that is different across all versions but class A method aMethod() is identical. I would like to update the method and write the update to versions v1 and v2 only.

如何

例如,如果我在 v1 中修改 source.cpp ,然后将其合并到 v2 将是合并冲突(因为 source.cpp v1 v2 中不同)。有什么办法可以避免冲突?如果不是,在这种情况下处理合并冲突的最佳方法是什么?
顺便说一句,我不想​​增加代码的粒度,以便将 aMethod()放在一个专用文件中,因为已经编写了很多源代码,并且

How can I do that?
If I modify source.cpp, for example, in v1, than merge it to v2 there will be a merge conflict (because source.cpp is different in v1, v2). Is there any way to avoid the conflict? If not, what is the best way to deal with the merge conflict int this case? By the way, I don't want to increase code granularity so that the aMethod() will be placed in a dedicated file, because there is already lots of source code written and there will be too much overhead for doing this for any such modification that I describe.

在此先感谢,

Daniel

推荐答案

您是否尝试过 git cherry-pick ?如果您从分支v1到分支v2进行 git merge,则所有在v1中而不在v2中的提交都将被合并,这不是您想要的。如果您只凭单挑选择一次提交,那么我认为不会发生合并冲突。

Have you tried git cherry-pick? If you do "git merge" from branch v1 to branch v2 all commits that are in v1 and not in v2 will be merged over, thats not what you want. If you just cherry-pick the single commit with your change I don't think there will be a merge conflict.

这篇关于使用git同时维护不同版本的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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