Tag Archive for 'tip of the week'

Subversion Tip of the Week

An Apache Subversion working copy can be created quite simply by running the ‘svn checkout’ command. However, sometimes you’ll want to have more control over the contents of your working copy; for example, when you’re working on a large project and only need to checkout a single directory.

In this post, we share two ways to get greater control over your checkout commands.

1. Checkout a particular revision

By default, Subversion performs a checkout of the HEAD revision, but in some instances you may wish to checkout a previous revision, for example when you’re recovering a file or directory that has been deleted in the HEAD revision.

To specify a revision other than HEAD, add the -r switch when performing your checkout:

svn checkout (URL) -r(revision number) (Location)

In this example, we are performing a checkout of the project as it existed at revision 10.

customizing working copy

2. Performing Shallow Checkouts

A standard Subversion checkout copies the entire directory, including every folder and file. This can be too time-consuming if you’re working on a large project, or too complicated if your project contains many different branches, tags and directories. If you don’t require a copy of your entire project, a ‘shallow checkout’ restricts the depth of the checkout by preventing Subversion from descending recursively through the repository.

To perform a shallow checkout, run the ‘svn checkout’ command with one of the following switches:

  • –depth immediates: checkout the target and any of its immediate file or children. This is useful if you don’t require any of the children’s contents.

  • –depth files: checkout the target and any of its immediate file children.

  • –depth empty: checkout the target only, without any of the files or children. This is useful when you’re working with a large project, but only require the contents of a single directory.

In this example we are performing a shallow checkout on a ‘bug fix branch’ located within the branches folder, and specifying that only the immediate file children should be included (–depth files):

customizing working copy 2

Looking for a cross-platform Subversion client? Get a free trial of SmartSVN Professional at www.smartsvn.com/download

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

Subversion Tip of the Week

SVN Revert

Apache Subversion’s ‘svn revert’ command allows you to discard local changes on a file or directory and replace it with the version in the repository. This saves you the overhead of performing a fresh checkout, and is also helpful when you need to quickly resolve a conflict.

To revert the changes on a single file, run the ‘svn revert’ command followed by the file path:

svn revert (working-copy)/filename

svn revert

It’s also possible to revert all the changes within an entire directory using the –depth=infinity switch. When this switch is added, any files that have been changed within the specified directory are replaced with their repository equivalent:

svn revert –depth=infinity (working-copy)

svn revert infinity

Useful Additional Commands

  • svn status

Before discarding your local changes, you may want to review exactly which files have been altered at the working copy level by using the ‘svn status’ command:

svn status (working-copy-path)

svn status

  • svn diff

The ‘svn diff’ command prints all the changes that have been made to human-readable files within the working copy, which is useful for identifying the file(s) you want to revert. Each line is prefixed by a character representing the nature of the change:

  1. + Line was added
  2. – Line was deleted
  3. A blank space represents no change

To run ‘svn diff’ enter the following command:

svn diff (working-copy-path)

svn diff

Looking for an easy-to-use cross platform Subversion client? Claim your free 30 day trial of SmartSVN Professional by visiting: www.smartsvn.com/download

 

 

Subversion Tip of the Week

Using SVN Move

Apache Subversion’s ‘svn move’ command allows the user to move files and directories and can be applied to both the working copy and the repository. The key difference between this command and ‘svn copy,’ is that ‘svn move’ also deletes the original file. This makes running ‘svn move’ equivalent to performing an ‘svn copy’ followed by ‘svn delete.’

…in the Working Copy

Running this command at the working copy level requires you to specify the file you’re moving and the location you’re moving it to:

svn move (working-copy-path)/item-being-moved (working-copy-path)/new-location

In this example we’re moving the ‘Release2’ item to the ‘Releases’ directory.

svn move

Note, you’ll need to perform a commit to send this change to the repository and share it with the rest of your team.

…in the Repository

It’s also possible to move items inside the repository. As this creates a new revision, you’ll need to supply a log message alongside the command:

svn move (repository-URL)/item-being-moved -m “log message” (repository-URL)/new-location

In this example we’re moving the item ‘Release’ to the ‘Releases’ directory.

svn move 2

Looking for an easy-to-use cross platform Subversion client? Claim your free 30 day trial of SmartSVN Professional by visiting: www.smartsvn.com/download

Subversion Tip of the Week

SVN Import

There are two main options when you need to add new file(s) to your Apache Subversion project: the ‘SVN Add’ command and ‘SVN Import.’ The advantage of performing an ‘SVN Import’ is that:

  • ‘SVN Import’ communicates directly with the repository, so no working copy or checkout is required.
  • Your files are immediately committed to the repository, and are therefore available to the rest of the team.
  • Intermediate directories that don’t already exist in the repository are automatically created without the need for additional switches.

‘SVN Import’ is typically used when you have a local file tree that’s being added to your Subversion project. Run the following to add a file/file tree to your repository:

svn import -m “log message” (local file/file tree path) (repository-URL)

In this example, we’re adding the contents of the “Release2” folder to the repository, in an existing ‘branches’ directory.

svn import 1

As already mentioned, intermediate directories do not need to exist prior to running the ‘SVN Import’ command. In this example, we’re again importing the contents of ‘Release2,’ but this time we’re simultaneously creating a ‘Release2’ directory to contain the files.

svn import create new folder

If you check the repository, you’ll see a new ‘Release2’ directory has been created. The contents of your ‘Release2’ file tree are located inside.

ubersvn import

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

Subversion Tip of the Week

Getting Help With Your Subversion Working Copy

When it comes to getting some extra help with your Apache Subversion installation, you will find plenty of documentation online and even a dedicated forum where SVN users can post their questions and answer others. However, Subversion also comes with some handy built-in commands that can show you specific information about your working copy, files, directories, and all of Subversion’s subcommands and switches. This post explains how to access all of this information from the command line.

1) SVN Help

One of the most useful features of command line Subversion is the instant access to its built-in documentation through the ‘svn help’ command. To review all of the details about a particular subcommand, run:

svn help (subcommand)

In the example below, we’ve requested information on the ‘unlock’ subcommand. The printout includes all the additional switches that can be used in conjunction with ‘svn unlock.’

svn help unlock

Alternatively, if you need to see a list of all the available subcommands, simply run ‘svn help.’

svn help

2) SVN Info

If you need more information about the paths in a particular working copy, run the ‘svn info’ command. This will display:

  • Path
  • Repository URL
  • Repository Root
  • Repository UUID
  • Current revision number
  • Node Kind
  • Schedule
  • Information on the last change that occurred (author, revision number, date)

svn info

3) SVN Status

This command prints the status of your files and directories in your local working copy:

svn status (working-copy-path)

svn status

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

 

Subversion Tip of the Week

Creating a New Directory in Apache Subversion

There are two ways to create a new directory in Apache Subversion. You can either create the directory in your working copy and then commit it to the repository as a separate operation, or simply create the new directory in the central repository.

1) Creating a directory in the working copy:

svn mkdir (working-copy-location/name-of-new-directory)

In this example, we’re creating a new directory called ‘Release2’ in the branches folder. You’ll need to perform a commit to send this new directory to the repository and share it with the rest of the team.

mkdir working copy

2) Creating a directory in the repository:

svn mkdir -m “log message” (repository-URL/name-of-new-directory)

mkdir url

3) The –parents Option

Note that regardless of whether you’re creating a new directory in the repository or in a working copy, the intermediate directories must already exist. If you need to create the  intermediate directories, you must use the –parents option.

In this example, we’re creating two directories in the ‘NewRepo’ repositories, a ‘Releases’ directory and a ‘Release3’ directory.

svn mkdir with parent switch

Looking for an easy-to-use cross platform Subversion client? Claim your free 30 day trial of SmartSVN Professional by visiting: www.smartsvn.com/download

Subversion Tip of the Week

Intro to the ‘svnversion’ Command

If you need to discover the revision number (or revision range, if working with mixed revisions) of your Apache Subversion working copy, you can use the svnversion command. This is particularly useful if your working copy contains mixed revisions, and you want to find out the range of revisions currently in your working copy. Run this command, followed by the location of your working copy:

svnversion (working copy path)

This will print either a single revision number or the revision range. In this example, the working copy contains files at revision 31 and revision 32:

svnrevision

Additional Useful Options

1) –no-newline

Removes the usual newline from the printed output.

svnversion –n (working copy path)

2) –committed

Lists the highest locally available revisions.

svnversion –c (working copy path)

3) –version

Prints the version of svnversion you’re using, and additional information such as compile date and copyright disclaimers.

svnversion –version

svnversion version

Looking for an easy-to-use cross platform Subversion client? Claim your free 30 day trial of SmartSVN Professional by visiting: www.smartsvn.com/download

Subversion Tip of the Week

Solving Conflicts with SmartSVN

Conflicts can be tricky for Apache Subversion users, but SmartSVN comes with a dedicated ‘Conflict Solver’ that takes the pain out of resolving them. SmartSVN’s built-in Conflict Solver combines the freedom of a general, three-way-merge with the ability to detect and resolve any conflicts that occur during the development lifecycle.

To access this conflict solver, open the ‘Query’ menu and select ‘Conflict solver.’

conflict solver

The contents of the two conflicted files are displayed on the right and left text areas, and the differences between the left and right content is highlighted by coloured regions within the text views.

Once you have finished editing your files, open the ‘Modify’ menu and select ‘Mark Resolved’ to mark the conflicting file(s) as resolved. In this dialog, you can also opt to:

  • Leave as is – apply no further modifications to the resolved file.
  • Take old – accept the version in the working copy, as it was before the update or merge  was performed.
  • Take new – the pristine copy after the update or merge was performed.
  • Take working copy – the pristine copy before the update or merge was performed.

If you’re working with conflicted directories, you have the option to ‘Resolve files and subdirectories recursively.’  If selected, all conflicting files and directories within the selected directory will be resolved.

Note, you must resolve all the conflicts before you can commit the file(s)/directories.

Not yet started with SmartSVN? Claim your free 30 day trial at www.smartsvn.com/download

Subversion Tip of the Week

Getting More Out of SVN Log

Apache Subversion‘s ‘SVN log’ is a useful command, allowing you to view the entire history of a directory, including who made changes to the directory, at what revision, the exact time, and any accompanying log messages.

In it’s most basic form, a simple ‘SVN log’ command will give you a printout of everything that’s changed in your entire directory, across all revisions:

svn log

However, there’s plenty of options if you need to tailor ‘SVN log’s output. If this is far too much information, you can specify a particular revision:

svn log -r14

svn log 2

Or, if you’re after all the available information about this particular revision, add the verbose option to your command:

svn log -r14 -v

svn log 3

Alternatively, if you do not need to review the log message, you can add the quiet option to suppress this piece of information:

svn log -r14 -q

svn log 4

Of course, both of these options can also be applied to an entire directory:

svn log -q
svn log -v

When the two options are combined, ‘svn log’ prints just the file names:

svn log -q -v

svn log 5

Looking for an easy-to-use cross platform Subversion client? Claim your free 30 day trial of SmartSVN Professional by visiting: www.smartsvn.com/download