University of Minnesota
College of Science and Engineering Labs Help Pages
/

Setting up a Repository

When choosing a directory to store your SVN repository, you should make sure there is enough space to store all of the projects that you will have in your repository. In order to set up a simple SVN repository, go to the directory where you want to set up the SVN repository and follow the steps below. Please note that these instructions are going to be relative to where you are making changes. You will have to remember the location of the repository that you set up.

Create the repository

  1. Make a new, empty directory:
    % mkdir <directory name>
  2. Change the permissions on the directory to be correct:
    % chmod 770 <directory name>
  3. Change the group :
    % chgrp <group_name> <directory_name>
  4. Change the permissions on the directory so that all files added to the directory belong to the correct group :
    % chmod g+s <directory_name>
  5. Create the svn repository :
    % svnadmin create --fs-type fsfs <directory_name>

Create a file structure for your project

The recommended file structure for a SVN project is:

  • Trunk - for primary project files
  • Branches - for copies of the trunk to allow parallel development that won't interfere with the main project
  • Tags - for snapshots of the project trunk that serve as stable versions

You will need to set up a temporary directory with this file structure.

  1. You will want to create the following temporary directory structure outside of your new repository. Your home directory is probably a good place for this temporary directory.
    % mkdir <project_name>
    % mkdir <project_name>/trunk
    % mkdir <project_name>/branches
    % mkdir <project_name>/tags
  2. Now move your entire tree of unversioned project files that you are going to put into Subversion to the '<project_name>/trunk/' directory.
  3. Set the correct permissions and group:
    % chmod -R 770 my_project/
    % chgrp -R <group_name> <project_name>/
    % chmod -R g+s <project_name>/
    

Import files into the repository

If your unversioned project files are on a lab computer or on the same machine as the repository:

% svn import <project_name> file:///<path_to_repository>/<svn_project> -m "Initial import"

If you have problems executing the import statement as given above using the file notation, or if you are importing project files from a laptop or home computer:

% svn import <project_name> svn+ssh://<host_name>/<path_to_repository>/<svn_project> -m "Initial import"

Where <host_name> is the name of a lab computer in the domain where your project is located.

Now a list of the subversion root directory should look like this:

% svn list file:///<path_to_repository>
<svn_project>

And a list of the project should look like this:

% svn list file:///<path_to_repository>/<svn_project>
branches/
tags/
trunk/

Cleanup

Once you can successfully checkout a copy of your project, you can delete the old local directory with your original, unversioned project files.

% rm -rf <project_name>/

Basic Commands

Checking out a copy

  1. Check out a working copy of a Subversion project:
    % svn co file:///<path_to_repository>/<project_name>/trunk/ <new_project_name>
    Where <new_project_name> is the name of the directory where you want the the files from the project, <project_name>, to be checkout.
  2. Check out a working copy of a Subversion project that is on a different domain:
    % svn co svn+ssh//<host_name>/<path_to_repository>/<project_name>/trunk/ <new_project_name>
    Where <host_name> is a the name of a computer which is on the same domain as the repository that you are trying to check out.

Updating your copy

To update your working copy with all of the changes that have been committed to the project repository:

  1. Change to the directory that you want to update.
  2. Update the directory:
    % svn update

When you update a directory, everything under that directory will be recursively updated. If you want to update your entire working copy of a repository, you just need to a svn update in the root directory of your working copy. You can also update an individual file in your working copy:

% svn update <path_to_file>/<file_name>

Check Status

To check the status of your working copy against the repository:

% svn status

There are several common statuses that file can have:

"M" - indicates that your copy of the file has been modified.
"A" - indicates that you have added the file to subversion, but have not committed the change.
"?" - indicates that Subversion doesn’t know about this file.
"C" - indicates a file content conflict that Subversion cannot resolve.

Commit Changes

When you commit any change, you will be prompted to add a message describing the changes that are being checked in.

  • To commit all of the changes to the svn repository that you made in your working copy, change to the root directory of your working copy and run:
    % svn commit
  • You can also choose which files you want to commit:
    % svn commit <file_name_1> <file_name_2> ...

See changes in your repository

  1. To see all of the changes that you have made in your working copy, change to the root of your working copy and run:
    % svn diff
  2. See all of the changes that you have made in an individual file:
    % svn diff <path_to_file>/<file_name>

Resolving Conflict

Sometimes Subversion can’t resolve differences between your working copy and the latest version in the repository. If you run y, Subversion will print out a “C” status for conflicted files.

When a conflict occurs, the following message will be printed out:

% Conflict discovered in '<file_name>'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: 

If you choose to postpone (p) the conflict, for each conflicted file, Subversion will create three new files -

  1. A copy of your file, with your changes, as it was before you committed it. It will be named: <original_filename>.mine
  2. A copy of the file as it existed when you checked it out. This file will be named: <original_filename>.r<old_revision_number>
  3. A copy of the newest version that exists in the repository. This file will be named: <original_filename>.r<new_revision_number>

You will need to figure out how to merge the versions manually within your working copy, then run:

% svn resolved <file_name>

Note: 'svn resolved' will remove the three files that Subversion created during the failed update. If you want to preserve any of these files, copy them to a different file name before you run 'svn resolved'. Once you have run 'svn resolved', you can re-run 'svn commit'.

If you need to, you can always delete your working copy of a file and do an svn update to check out the latest version of that file. Example:

% rm <path_to_working_copy>/<file_name>
% svn update <path_to_working_copy>/<file_name>

This will restore <file_name> with a fresh copy from the repository.

Getting Help

  1. For general SVN help, run:
    %  svn help
  2. For help with a specific SVN command, run:
    % svn help <svn_command>

Sharing with Others

If you have multiple people who want to work on a project you can send an email to operator [at] cs [dot] umn [dot] edu to get a group set up. You will need to include a name for the group in the email, this should be 8 characters or fewer, the names of everyone that needs to be added to the group, and the University Internet ID or CS username of each person that needs to be added to the group.

Once you have a group create, you will need to set the group for the svn repository. Go into the directory above the root directory of the svn repository that you want to share with the group and run the following command:

% chgrp -R <group_name> /<svn_root_directory>

Every time that you create a new project, you will have to make sure the correct group is set by running the same command on the new project directory.

This is a very minimal introduction to svn. There are a lot of great online resources that will help you really dig in and learn how to use it. Here are a couple to get your started:

Contact: 1-201 Keller Hall, 200 Union St SE, Minneapolis, MN 55455   Phone: (612) 625-0876   Email: operator@cselabs.umn.edu