Can CVS and Subversion be set to ignore whitespace in merging?

Leigh Caldwell picture Leigh Caldwell · Oct 11, 2008 · Viewed 11.5k times · Source

CVS and Subversion both have a handy merge feature so that when you update a source file that you have modified, it merges in changes that others have made on the same file.

However, if your changes and the other ones are incompatible - generally if you have both changed the same parts of the code - it will create a conflict. Both stretches of source code will be included into the merged file and you need to manually sort out which changes to keep. All fine so far.

My problem is that some of us use different development environments (Netbeans versus vi if you must know) and Netbeans has an auto-indenting feature which re-indents the code. Therefore, when we merge changes, we sometimes get huge conflicts which are mostly caused by simple changes in indentation and are not genuine changes to code. Often these create hundreds of lines of apparent conflicts which have to be manually resolved, but usually they come down to just a few lines of real changes. A similar situation occurs when someone's editor changes unix to Windows newlines or vice versa.

So - can I set merge to ignore these "conflicts" when comparing the two versions? Diff has the --ignore-space-change or -b option and I would like to have essentially the same feature available in cvs or svn. We use each tool on different projects so I would be happy to have the answer for either or both.

Two final notes:

  • clearly the merge process would have to make an arbitrary choice as to which version of the whitespace to use in the merged file. I'm fine with that - we can always reformat it again later.
  • I could avoid some of this by being more disciplined and checking in more often - acknowledged and understood. But I am not perfect.

Answer

Peter Parker picture Peter Parker · Oct 11, 2008

For SVN: In commandline tool, there is the option -x which you can set to "b" or "w" to ignore space changes resp. all spaces.
You can also supply a third party tool for doing the merges. So if you have a merger which ignores whitespaces, you can use this one. TortoiseSVN, as always, is a frontend to all parameters, so it will support for ignoring whitespaces as well.

The svn merge command is described here. The option you need is --diff3-cmd