
Who’s afraid of the big bad merge?
February 1, 2010A common objection to using parallel development is the fear of the inevitable merging required to reintegrate the changes as the development proceeds. In this post I will take a look at some of the issues that arise from managing parallel development and, perhaps more importantly, provide some guidance on how to avoid the pitfalls of parallel development.
Simple Merges
The most basic merge is a very straightforward (although, as we shall see, can have hidden complexities).
In this example changes to the file are merged between the two branches resulting in a new revision on the upper branch. Since the changes are to different parts of the file the merge can be performed automatically, resulting in a file containing both sets of changes.
The most obvious limitation of these simple merges is that the file must be ‘mergeable’, which for most tools means the file must be record oriented. Text files are a collection of records, one for each line in the file. Binary files tend to be resistant to merge unless a special tool is provided (MSWord can merge two documents with reasonable accuracy).
Conflicting Merges
Sometimes a merge involves changes to the same records (the same lines in a text file) in the same file. The illustration below shows just such a merge.
The most notable feature of this merge is the line marked ‘Developer resolves conflicts’. Conflicting merges require human intervention to decide which parts of the conflicting lines should be accepted into the final merged version of the file.
Sometimes these conflict resolutions will require more than a simple decision about which line from the two changes should be adopted and the developer will need to rework both changes to make them work together. Fortunately the majority of merge conflicts are relatively straightforward providing integrations are performed frequently.
Renamed and Moved Files
While merging a file’s content is commonly supported by version control tools, tracking renamed and moved files during a merge operation is less well supported but in todays software development world, where refactoring is common, it is increasingly essential.
The problem with renamed and moved files are summarised in the following illustration.
In the top branch file2 has been modified, but in the lower branch file2 has been both modified and renamed to file3. The desired result, shown in the final version to the right, contains the changes from both file2 in the top branch and the changes in file3 in the lower branch. But most importantly, the file has also been renamed to file3 in the upper branch.
Rename/move conflicts
Merges involving renames do not necessarily run smooth. Not only are they subject to the same content merge issues as the simple file merge but also the problem when the file is renamed/moved in both branches. This situation is illustrated below.
In this case the tool has chosen to include both renamed files. This may not be what was intended, so care must be taken when dealing with renamed and moved files. Other tools will display a conflict and require user intervention to decide the correct name to assign to the file in the merged dir1.
Mitigation
Before moving on to some other issues you will encounter when using parallel development, we pause briefly to consider how to avoid, or at least mitigate, some of the issues mentioned so far.
Firstly, despite the impression the previous sections may have conjured, merging is not fraught with perils. After many years of managing parallel development on projects ranging from the simple to very complex, I can assure you that, with a little common sense and some forethought the issues can be minimised (but seldom completely eliminated).
- Merge as early as you can, and then merge often to keep each merge as small and manageable as possible.
- When you have input to a project’s design, ensure a sound architecture. This will minimise overlapping changes and consequently merge conflicts.
- If you identify files that are merged often, try to decompose the file into smaller files to avoid high merge rates. (This is common with files used for configuration or files containing a lot of utility code.)
- Keep refactoring on one branch. Renaming and moving files can cause tricky merge issues when performed on many branches.
Now, on to some issues that, while not unique to parallel development, can make your life difficult if not managed properly.
Pages: 1 2




[...] Power from Simplicity Effective IT Systems Management « Who’s afraid of the big bad merge? Parallel development: theory and practice February 10, 2010 Having spent the past couple [...]