Many software projects feature a NEWS (or ChangeLog) file where the most important changes are documented. One way of maintaining such a file is to request an entry for each contribution. However, this bears potential for merge conflicts: Two separate contributions will then change the NEWS file in the same place and thus are incompatible.

Are they really?

In Git, there are three built-in merge drivers:

  • text for text files: Will merge non-conflicting changes and introduce the notorious conflict markers <<<<<<<, ======= and >>>>>>> for conflicting changes
  • binary for binary files: Will prefer "our" contents and mark the file as conflicted
  • union for text files: Will append lines introduced by conflicting changes in a random order

Normally, the text or binary driver is used, depending on the file type. For the NEWS file, the union driver would be ideal. It is possible to specify a merge driver for each file in the repository (wildcards allowed). This is done by adding an entry to the .gitattributes file in the root of the repository, in our case

/NEWS merge=union

Create the file if it does not exist. Here, /NEWS is the absolute path of the NEWS file in the repository. Don't forget to commit this file to the repository. After that, entries added to the NEWS file by different branches all appear in the resulting file after merging, ready for being sorted just before the release.

I have prepared a small demo on GitHub. It seems that this feature has been around forever, but it is not as widely known as, say, the .gitignore file.

One more hint: If new items are added to the top of the NEWS file, the order of the entries will match the (reverse) order in which the branches are merged.

Finding files in subdirectories

How to locate your files no matter what the subdirectory is Continue reading

From zero to tested in five minutes

Published on April 14, 2015

xpreen — Integrating xpra with GNU Screen

Published on August 07, 2013