Working with SVN

The purpose of this tutorial is to teach you how to work with the SVN source control system. You will learn how to configure your SVN repository, upload projects and files to it, check out (import) projects and files from it and commit changes which you have made to files.

Purpose

SVN, or Subversion, is a source control system intended to allow a team or group to work on the same files and projects simultaneously, and to be able to revert file and project states back to previous versions.

Adding an SVN Repository

Before you can add projects to or export projects from SVN, you must define your SVN repository settings.

Note:

To access a repository, make sure that an SVN server is already configured.

 

 

Instructions on how to complete a procedure

To add a new SVN repository:

  1. Open the SVN perspective by going to Window | Open Perspective | Other | SVN Repository Exploring.

  2. In the SVN Repositories view, click the Add SVN Repository button on the view's toolbar -or- right-click within the SVN view and select New | Repository Location.
    The Add SVN Repository dialog will open.

  3. Enter the information required to identify and connect to the repository location:

  • URL - The URL on which your repository is located.

  • Authentication - The user name and password you use to connect to SVN.

  1. Click Finish.
    Your SVN repository will now be added to the SVN Repository view.

 

Back to Top

Sharing Projects

Through SVN, projects can be shared and worked on by numerous team members.

 

 

Instructions on how to complete a procedure

The following steps demonstrate how to upload a project to your SVN repository location:

  1. Create a new PHP project called "MySVN Project".

  2. Within the project, create a PHP file called "SVNFile1" with the following code:

<?php

//This is a new file

?>

  1. In PHP Explorer View, right-click your project and select Team | Share Project.
    A Share Project dialog will open.

  2. From the repository list, select SVN and click Next.

  3. Select 'Use existing repository location', and select your repository from the list.

  4. Click Finish.

  5. Depending on your authentication settings, a dialog might appear asking you to provide authentication information.
    Re-enter your password and click Next. (Mark the Save Password checkbox to ensure that this screen does not reappear.)

  6. A Commit dialog will open. Enter the comment "I am uploading files to SVN." and click OK.

  7. In PHP Explorer View, your project will now have a repository icon , indicating that it is in SVN.

  8. Once you have committed your files, other team members will be able to access and change the files.

 

The instructions below explain how users can check out (import) projects from SVN, edit them and upload their changes.

Back to Top

Checking Out Projects from SVN

Once projects are placed on the SVN repository, they can be checked out (imported) by anyone with access to that repository.

 

 

Instructions on how to complete a procedure

The following steps demonstrate how to check out (import) projects from SVN into your workspace:

  1. Delete the 'MySVN' project from from your workspace in order to simulate being a new user who has not previously had access to this file.
    Note: Deleting the project from your workspace will not delete it from SVN.

  2. Go to File Menu and select Import | Projects from SVN.

  3. Click Next.

  4. Select your repository.

  5. Click Next.

  6. A 'Select Resource' dialog will appear. Expand the nodes until you see your project (by default, this will have been placed under 'Trunk').

  7. Select your project and click Finish.
    A 'Check Out As' dialog will appear.

  8. Leave the 'Check out as a project with the name specified' option marked and click Finish.

The project will now be imported into your workspace.
Note that the project will have an SVN repository icon in your PHP explorer view.

 

Now that you have imported a project from SVN into your workspace, you can add files, edit existing files and commit your changes to the SVN repository. (See below).

Back to Top

Adding Files to Existing Projects

You can add files to existing projects in the SVN repository and commit them so that other users can access them.

 

 

Instructions on how to complete a procedure

The following steps demonstrate how to add and commit a file into an existing project:

  1. In your SVNProject, create a new PHP file, called "SVNFile2" with the following code:

<?php

//Another new file

?>

  1. Save the file.

  2. In PHP Explorer View, select the file, right-click and select Team | Commit.

  3. A Commit dialog will open.
    Enter a comment "Another new file added." and click OK.

The file will be committed to SVN and will be accessible by other users.

Back to Top

Making Changes, Comparing Changes, and Committing Changes

Once files are stored on SVN, you and all other team members can make changes to the files and commit them. Before committing changes you have made to a file, you can compare the file stored locally in your workspace to the file stored on the SVN repository.

Making and Comparing Changes

 

 

Instructions on how to complete a procedure

The following procedure demonstrates how to make changes to files and comparing local files to files in the repository:

  1. Open SVNFile1 in your SVNProject.

  2. After the text "This is a new file.", add "I have made a change".

  3. Save the file.
    In PHP Explorer view, the file and project will have a ">" suffix, indicating that a change has been made which has not yet been committed.

  1. So far, the changes have only been saved in your workspace. In order to compare the local file to which you have made changes with the one sitting in the SVN repository, right-click the file in the PHP Explorer view and select Team | Synchronize with Repository.

  2. Click Yes when asked whether to open the Team Synchronizing perspective. (Check the 'Remember my decision' box to prevent this prompt from appearing in the future.)

A Text Compare dialog will open showing the local file you have just made changes to (in the left-hand window) as compared to the file in the repository (in the right-hand window).
The change you have made will be highlighted.

SVN Text Compare View

In addition, the Synchronize view will have opened in the left hand-side, displaying the file to which you have made changes. The file will have a grey arrow icon indicating that changes have been made which need to be synchronized with the repository.

Committing Changes

Once you have edited your file and compared it to the one in the repository to ensure that the changes are correct, you can commit your changes.

 

 

Instructions on how to complete a procedure

To commit your changes to the repository:

  1. From the Synchronize view, click the 'Commit All Outgoing Changes' button.
    -Or- In PHP Explorer View, right-click your file and select
    Team | Commit.

  2. A Commit dialog will open.
    Enter the comment "I have made changes to SVNFile." and click Finish.

Your changes will now be committed to SVN and all users will be able to access the file.

Back to Top

Replacing Files with Older Versions

Using SVN's version control system, you can revert back to older versions of files if incorrect changes have since been made.

 

 

Instructions on how to complete a procedure

This procedure demonstrates how to replace your file with an older version:

  1. In the PHP Explorer view, select your SVNFile1 and from the right-click menu select Replace with | Revision.
    A Replace with Revision dialog will open.

  2. Select Revision and click Select.
    A Select Revision dialog will open, listing the various times the file has been committed (revisions).
    As committed changes have been made twice (once during the original upload and once when you edited the file), 2 revisions should be listed with their relevant comments.

Select Revision Dialog

  1. Scroll between the two revisions.
    To return the file to it's previous state, select the second revision in the list (containing the comment "I am uploading files to SVN.") This is the original state the file was in when it was first uploaded.

  2. Click OK.
    You will be returned to the Replace with Revision dialog, which will now have a revision number in the Revision box.

  3. Click OK.
    You will be prompted to confirm that you would like to replace the revision.

  4. Click Yes.

Your project will be reverted to the old one and the line "I have made a change" will be removed from SVNFile1.

Back to Top

Deleting Files from SVN

You can delete a file from the SVN repository so that the file will no longer be available to any users.

 

 

Instructions on how to complete a procedure

This procedure demonstrates how to delete a file from SVN:

  1. Open the SVN Repositories view.

  2. Expand the nodes to find your project.

  3. Right-click the file you would like to delete and select Delete.
    A "Commit Deletion" dialog will open.

  4. Enter a comment if required.

  5. Click OK.

The file/project will be deleted from your SVN repository.

Note:

This action will delete the file from the SVN repository and not just from your workspace. This file will no longer be accessible by any users.

See the Subversive User Guide for more information on the SVN plugin.

Back to Top

 

 

Related Links:

Quick Start

SVN

Using SVN

Configuring an SVN Connection

Uploading Projects to SVN

Importing Projects From SVN