Support different versions of code at the same time with git

I have a code that I have to optimize. I would like to support a set of code versions (each version can be described as a set of some functions, optimizations) at the same time. In the end, I will decide which version is the best. I do not want to combine these versions with fewer versions. However, I would like to be able to make a (minor) modification to the (large) source file that can redirect versions, and I want this modification to be written across several (possibly all) versions. How can I achieve this with git?

For example, consider 3 versions: v1, v2, v3 and the source code source.cpp, which has a lot of code that is different from all versions, but the class A method aMethod () is identical. I would like to update this method and record the update only in v1 and v2 versions.

How can i do this?
If I change source.cpp, for example, in v1, than merge it into v2, a merge conflict will occur (since source.cpp is different in v1, v2). Is there a way to avoid conflict? If not, what is the best way to deal with a merge conflict in this case? By the way, I do not want to increase the detail of the code, so aMethod () will be placed in a dedicated file, because a lot of source code has already been written, and there will be too much overhead for this modification that I describe.

Thanks in advance,

Daniel

+3
source share
3 answers

Have you tried git cherry-pick ? If you do a “git merge” from v1 branch to v2 branch, all commits that are in v1 and not in v2 will be merged, this is not what you want. If you are just cherry - choose a single fixer with your changes, I don’t think there will be a merge conflict.

+3
source

If the optimizations you do are mostly independent of each other, you can branch out for each individual optimization from your starting point, and when you want to test some combination, make another branch from the starting point and merge the octopus from the desired optimizations.

+1
source

It would be nice to test different alternatives in one source file.

As you noted, git merging is for merging versions, which is especially useful when distributed teams want to work without stepping on each other.

This will not help you keep the files separate. A cherry kicker can fill in the gap, but unlike the equivalent of the darks, it does not use history and may not work in many cases. Presenting your minor changes in topic threads, you can work, but you will need to depend on an early, general revision and only merge with them, not in them.

Since you control everything, you can test divergent algorithms, keeping them compatible and synchronous, and you don't need multiple branches.

0
source

Source: https://habr.com/ru/post/1496364/


All Articles