Conflict Markers in Code – Justification for Leaving Them

coding-stylecommentsversion control

Consider conflict markers. i.e.:

<<<<<<< branch
blah blah this
=======
blah blah that
>>>>>>> HEAD

In the particular case which has motivated me to post this question, the team member responsible had just completed a merge from upstream to our branch, and had in some cases left these in, as comments, as a sort of documentation over what had just been resolved. He left it in a compiled state, tests passing, so it's not as bad as you would think.

Instinctively though, I really took objection to this, however being devils advocate to myself I can see why he might have done it:

  • because it highlights to other team developers what has changed as a result of the merge.
  • because those who are more expert with the particular pieces of code can then address the concerns illustrated by the comments so that he doesn't have to guess.
  • because the upstream merge is a right pain and it can be difficult to justify the time to resolve everything well and completely, so some semi-complete FIXME notice is necessary, so why not use the original conflict as a comment to document this.

My objection was instinctive, but I'd like to be able to justify it rationally, or see my position more wisely. Can anyone give me some examples or even experiences where people have had a bad time with someone else doing this and/or reasons why it's bad practice (or you can play devil's advocate and support it).

My own immediate concern was that it would clearly have been annoying if I had been editing one of the files concerned, pulled the changes, got real conflicts, but also pulled in the commented ones. Then I would have had a very messy file indeed. Fortunately that didn't happen.

Best Answer

This is clearly wrong. It is the job of the version control system to keep track of changes, and it is the job of diff tools to show what has changed as a result of the merge. There should be a comment in the commit log, and maybe in the code, explaining what was changed and why. However, IMHO, leaving the conflict markers in as comments is the same as leaving dead code around.

Related Topic