Git: support 2 branches with 99% of the same code

I am working on a Java project with Maven, where I need to deploy it very often in two different weblogic environments. The only differences between the two deployments are the totality of the changes in these two files: pom.xml and weblogic.xml . The remaining files are the same.

We create two GIT branches for this: dev and parallel-dev .

But we have a lot of problems with saving and merging changes between these two branches.

All changes are made in the parallel-dev branch, and as soon as this code is reviewed and approved, we merge it into the dev branch, except for those two files that do not need to be merged (if only the pom version is modified - in this case we only need to merge version change, but not the rest of the changes in pom.xml). This is a little dirty.

I think this method is rather confusing and can be improved, but cannot really see how to do it. I would just like to leave one branch for this process and avoid all these crazy mergers that we face.

Any advice would be highly appreciated.

- EDIT -

The difference in pom.xml is just another profile for the parallel dev branch:

 <profiles> <profile> <id>parallel-dev</id> <activation> <activeByDefault>false</activeByDefault> </activation> <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> <resource> <directory>src/test/resources</directory> <filtering>true</filtering> <includes> <include>env.properties</include> <include>more.properties</include> ... </includes> </resource> </resources> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <excludes> <exclude>env.properties</exclude> <exclude>more.properties</exclude> ... </excludes> </testResource> </testResources> </build> </profile> 

In weblogic.xml difference is name-context-root name and link to the library (this library also has parallel dev and dev branches).

+5
source share
2 answers

I would do the following:

  • Isolate the changes you made to these two files in the dev branch.
  • Destroy the dev branch and recreate it from the parallel-dev branch.
  • Repeat the changes to the dev branch in the new commit.

Now, whenever a new development occurs on the parallel-dev branch, switch to the dev branch and run:

git rebase parallel-dev

(or equivalent operation in your GUI). This will reset the dev branch to the newest version of parallel-dev and reapply the sandboxed change to these two xml files.

If the change to parallel-dev happened with an overlap with isolated changes, you will still have merge conflicts, but otherwise you should be good to go. (Although I would double check the .xml files to be safe)

0
source

I would create two Maven submodules in your project, keeping the code in the parent module, but the different configurations in the submodules. This way you do not need two different branches, and therefore you get rid of all merge conflicts associated with them.

Corresponding part of the parent POM:

 <modules> <module>dev</module> <module>paralleldev</module> </modules> 

And in the submodules, you just need to create a specific POM and the src/main/resources folder, and include sources from the parent in the POM. Corresponding submodule part:

 <build> <sourceDirectory>../src/main/java</sourceDirectory> </build> 

You can do even more with the Maven Compiler Plugin - see here: Maven Guide to Using When You Cannot Use Conventions

0
source

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


All Articles