subversion: diff between branches

Emmanuel Bassi just showed me how to get a diff between subversion (svn) branches. It’s not obvious. It should be easier. But here it is:

  • Discover the revision numbers: You need to know the revision numbers of the latest versions in each of the branches. It looks like svn log is the only way to do that. If your svn has the –limit option then you can see the revision number by cding into the branch’s directory, and typing svn log –limit 1. Otherwise, just look at the start of the svn log output manually. That will give you two numbers, such as 123 and 145.
  • cd into one of the branch directories, such as trunk.
  • Supply the revision numbers to the svn diff command: svn diff -r123:145

I’m much rather do something like “svn diff ../branches/thing-1-0”. Surely that should be possible?
Also, here’s how to get a diff with the -p option, so that patches have function names to make them more readable.

10 thoughts on “subversion: diff between branches

  1. I was about to say the same as Ross, but too late.

    and for the version of a branch, use ‘svn info’ and look for ‘Last changed rev’

  2. Not only does the path method from Ross work, your solution unfortunately doesn’t (How should it? It simply displays all changes in the branch you call it from between two revision numbers. Revision numbers in SVN are global over the whole repository)

  3. Jens, as I understood it, the revision numbers are unique to a branch, so the same revision number can’t be used for two branches. It seems to work.

  4. I’m afraid Jens is correct. The revisions are unique to a branch, but it depends on what path you are doing the diff on.

    Example, if you commit changes to the branch, they will have commit revisions. Then if you do a diff on trunk using a range that includes the aforementioned revisions, notice you will not see the changes. That’s because those revisions only apply to the branch, not trunk.

    The best way to see differences between branches is using the method from Ross Burton’s example.

  5. The svn diff [path] [path] worked for me, but unfortunately I couldn’t get it to work with relative paths. Any ideas?

Comments are closed.