Source control systems such as Rational’s ClearCase and the open source products CVS and Subversion, make it relatively easy to branch an application’s source code to produce, say, different versions for different customers or maybe work is taking place that can be carried out by two developers independently. Merging the branch back into the main code stream can be achieved using a variety of tools, for example TortoiseSVN, for Subversion, or the brilliant Beyond Compare, which compares files and directories rather than working on the source control system directly.
Notice the last sentence doesn’t include the word “easily”. That’s because it isn’t, particularly when both streams have had changes applied and/or someone other than the original developer is carrying out the merge.
The pain of merging can be eased by applying a few simple rules.
- Make sure your coding standards have a comment block defined that goes at the start and end of every change. The comment block should show the developer, date of change, reference to the bug or business requirement/technical design associated with the change and a concise but informative description of the change
- Coding standards should also advise on whether unwanted code is commented out or removed. Whichever technique is adopted it should be consistently applied and the same comment block header and footer format used as if making changes to the code
- When checking code back into the source control system a sensible and detailed description of the change, including reference to the bug or business requirement/technical design associated with the change must be entered. It’s not acceptable to put nothing or a banal statement such as “Changed made”
- Code reviews must be carried out and should include a check of the source control descriptions and possibly also review the changes made between the two version in source control to verify that each change has the correct comment blocks
- When complete build the application and test it. Don’t leave this until the next formal build as any knowledge gained during the merge may be forgotten