Tag Archive for 'svn diff'

Subversion Tip of the Week

Apache Subversion supports the creation and use of ‘patches’ – text files containing the differences between two files. Patches specify which lines have been removed, added and changed, and are particularly useful when you don’t have write access to a repository. In these instances, you can create a patch file showing the changes between a file as it exists in the repository, and the version in your working copy. Then, you can create a ticket and attach your patch file for someone with repository write access to review and commit the accepted changes to the repository.

To create a patch file, you first need to review the differences between the specific files/revisions you are targeting using the ‘svn diff’ command. In this example, we are examining the differences between the version of the project in our working copy and the central repository.

tip of the week

If you’re satisfied with the differences ‘svn diff’ has identified, run the following command to create a patch:

svn diff > patch_name.diff

tip of the week 2

All the changes will now be written to a patch on your local machine.

tip of the week 3

You can now send this patch to a user who does have write access to the repository.

Creating a Patch Between Revisions

Alternatively, if you want to create a patch containing the differences between two revisions, run the following command:

svn diff r:(revision)(revision) (working-copy-location)

Followed by:

svn diff > patch_name.diff

Again, this patch file can now be submitted to someone with write access.

Want more advice on your Apache Subversion installation? We have a full series of SVN refcards for free download, covering hot topics such as branching and merging, and best practices. You can find out more at www.wandisco.com/svnref

Reviewing Changes with Subversion’s ‘SVN Diff’

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)

svn diff

  • 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

svn diff 2

This command also works at the repository level.

svn diff 3

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.


Subversion Tip of the Week

The ‘SVN Diff’ Command

‘SVN Diff’ is a command for highlighting the differences between two paths. This is useful in a number of common scenarios:

1) Comparing versions of the same file, in different locations

Your project may contain different versions of the same file, for example one version in the trunk and one in a branch. To flag up the differences between the two versions, use the following command:

svn diff (repository-URL/trunk/filename) (repository-URL/branches/filename)

In this example, we are comparing a file called ‘Admin Guide’ that appears in both the trunk and in a branch called ‘Admin Text.’

This will list information such as the revision the file is at in both the trunk and the branch, alongside a print-out of the differences.

Tip. If you see the following error message when entering the ‘svn diff’ command:

OPTIONS of (repository URL) 200 OK (repository URL)

It usually means you entered the repository URL incorrectly – go back and check for typos!

2) Comparing your project/files at different revisions

As Apache Subversion remembers every change committed to the repository, it is possible to compare specific files, or even your whole project, at different revisions.

To compare two revisions of your project, the following command can be used:

svn diff (repository-URL) -r(Revision):(Revision)

In this example, we are comparing revision 5 of our repository with the head revision.

If you want to compare the differences between two revisions of a specific file, you simply add the location of the file and the filename to your command:

svn diff (repository-URL/file-path/filename) -r(Revision):(Revision)

In this example, we’re comparing revisions 8 and 10 of a text file named ‘Notes,’ which is located in the trunk:

Tip. The ‘SVN Diff’ command ignores the ancestry of files by default, to alter this add the ‘–notice-ancestry’ switch.