Sometimes you need to review the differences between files and revisions, for example before you commit your changes to the repository or when you’re trying to pinpoint the revision you need to revert to. This is when Apache Subversion’s ‘svn diff’ command comes in handy, allowing you to see the differences between files and revisions by printing a line-by-line breakdown of human-readable files. This helps by showing you exactly what has changed in the specified file, at the specified revision. The results include lines prefixed by a character representing the nature of the change:
-
+ Line was added
-
- Line was deleted
- A blank space represents no change
The ‘svn diff’ command can be used to perform several different tasks:
-
View Local Modifications
When ‘svn diff’ is performed on a working copy, it prints line-by-line information on all local modifications:
svn diff (working-copy-path)
- Compare Different Revisions
To use the ‘svn diff’ command to compare different revisions of the same file, use the ‘-r’ switch:
svn diff -r(number):(number) (working-copy-path)/filename
This command also works at the repository level.
Additional Options
-
–notice-ancestry
By default ‘svn diff’ ignores the ancestry of file(s), but you can force Subversion to take ancestry into consideration by adding the –notice-ancestry switch.
-
–show-copies-as-adds
By default, ‘svn diff’ displays the content difference for a file created by a copy command, as a delta against the original file. Adding this switch forces Subversion to display the copied content as though it’s a brand new file.