Merge_branches - PIK-LPJmL/LPJmL GitHub Wiki

Merge branches in SVN

For working with git, please see the [git userguide](git userguide)

Check diff

First need to check differences between the branches you want to merge. This can be more easily done with differencing and merging tools:

KDiff3 pocket-guide

link to Handbook

Checkout the two branches and upload the respective directories in KDiff3.
By default:

  • A is the base dir
  • B is the destination dir (where changes will be saved)

or even better:

  • A is the branch to be merged
  • B is the old trunk from which A was developed
  • C is the current branch (or trunk)

Additional settings: No tick on Merge; Swap/copy Names.

Click Ok and you will get an overview of the differences between directories and files encoded in colors:
>Black: This item doesn’t exist in this directory.
>Green: Newest item.
>Yellow: Older than green, newer than red.
>Red: Oldest item.

The program merges automatically the things where is clear what is needed to be done, but you need to check all these automatic choices. It leaves unsolved the conflicts where you have to make a choice (manual merges).

Most important directories to look at are:

  • include
  • src
  • par
  • config
  • files in the main folder (like .conf) are not that relevant when merging

Proceed folder by folder. For a shorter loading time, when starting the program, you can either (i) load one folder per time, and or (ii) do a make clean, to remove all the .o files. Start e.g. with include and proceed alphabetically file by file.

Good practice is to create an external file with notes on the choices you make (e.g. dir/file; line number; comment).

GGG: three versions are the same, don´t need to do anything
BGB: righ-click on operation column > do nothing
GGR: double-click on file; button merge; check diff; solve conflicts; save.

How to solve conflicts:
ctrl+up/down: move to previous/next conflict
ctrl+1/2/3/manual: choose version A/B/C, you can also choose more than one and in the order you want, as well as modify manually the code.
ctrl+S: save (then the status of the file should appear as “done”)

move on to the next file, etc.

at the end, when all conflicts are solved, in principle you should have only GGR, GGG, GGB, no Y.

Sometimes the lines are not correctly aligned. You can align them manually:

  • select line in A and Ctrl+Y
  • repeat for B and C
    note: if you have solved conflicts already above that line they will be erased, and you have to restart from the begining of the file.

Settings: In case too many files are conflicting, you might want to ignore some differences, e.g.:

  • due to different line end styles (Unix or DOS)
    change this setting in the pre-processor commmand: Settings > Configure KDiff3.. > Diff > Preprocessor command: sed “s/+/ /g”
    (or you can use the dos2unix command in linux to change that directly in the code)
  • due to C style comments
    change this setting: Settings > Configure KDiff3.. > Diff > check-mark on Ignore C/C comments
    (sed “s/\/\[^\\/]\\///g” also seems to e.g. remove the file headers and show them as white space)

Note: after changing a setting you have to reload (Press F5) and sometimes also to restart the entire program.

⚠️ **GitHub.com Fallback** ⚠️