Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maintain different versions of the code simultaneously using 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?

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.

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.

Thanks in advance,

Daniel

like image 504
Daniel Avatar asked May 06 '26 13:05

Daniel


1 Answers

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.

like image 171
awi Avatar answered May 09 '26 02:05

awi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!