Ignore whitespace in a Subversion diff

SubVersion It’s a common problem developers face – how can I see just the changes that have been made and ignore all the line ending changes? This tends to happen when you have members of your team committing changes when they have checked out the code onto different operating systems, be it Windows, Mac of Linux.

svn diff doesn’t really have a built in option for ignoring whitespace, but gnu diff does, and it is possible to use it within an svn diff command by using –diff-cmd

If you want to see the differences between 2 files, and ignore whitespace you use

diff -w /path/to/file1 /path/to/file2

or for a contextual diff

diff -wu /path/to/file1 /path/to/file2

To use this with svn you simply pass this argument in with diff-cmd like so

svn diff --diff-cmd diff -x -wu $svn_path_1 $svn_path_2

Comparing between the trunk and a branch of a project:

svn diff --diff-cmd diff -x -wu svn://subverison-server/project-name/trunk svn://subverison-server/project-name/branches/my_changes

Comparing between 2 revisions of an svn path:

svn diff --diff-cmd diff -x -wu svn://subverison-server/project-name/trunk@1234 svn://subverison-server/project-name/trunk@1299
# or
svn diff -r 1234:1299 --diff-cmd diff -x -wu svn://subverison-server/project-name/trunk

Leave a Reply

Your email address will not be published. Required fields are marked *