Instructions on using Subversion (SVN) to manage projects, starting from scratch.
We assume the userid is Background: There is a repository, that stores all of your code and changes, which consists of a nested set of directories; you only interact with the repository through svn commands. A local working copy exists for projects that you have “checked out” of the repository. Although you may check out projects anywhere you have permission, it is good practice to keep them all in one place. Also, please note that svn works by taking differences of files, and is space efficient for ascii (text) files. Be very careful with binary files! In general, svn will save a new copy of the binary file each time it
is changed, so you shouldn’t add binary files to the repository (e.g. .doc, .ppt, .pdf, .jpg, etc.) if you plan to change them often.
1) Create a repository directory
foo for the example below
2) Create a working directory
- new project repositories will be created and stored here.
3) Establish a project called newproj
- working copies of projects will be created and stored here.
- you can have such a directory anywhere, and create lots of them if you like (such as an svnwork directory in different directories for different projects), but it’s handy to collect them all in one place.
4) Establish a working copy of the new project
svnadmin create /home/disk/foo/svn/newproj
- svn is fussy about paths, so include the full path.
- this project is established, but empty. To add files we first need to establish a working copy.
5) Add directories and files to the working copy
- we’re in the working directory now.
svn co file:///home/disk/foo/svn/newproj
- svn uses URI references; file:// says “look for a local file.”
- to check out the project from a remote location, use:
svn co svn+ssh://mymachine.atmos.washington.edu/home/disk/foo/svn/newproj
- svn stores this info, and will ask you for a password from this location (e.g. from home) whenever you need to interact with the repository.
- we now have a local copy of the empty project newproj.
6) Commit the working copy of the project to the repository
- add files and directories in the project working directory.
- here’s a standard directory configuration:
- use for tagging a version for release as version of the project.
svn add *
- add all directories and files you created in and below
7) Add/revise files
- an editor will emerge, where you should enter notes for a log.
- if you do this from a remote location, svn will ask you for a password and automatically go through ssh.
8) Updating working copies
cp ~foo/proj/*.f ./src/
- i.e., copy code from some other location to place under version control.
- you generally should forget about using ~/foo/proj.
svn add ./src
- if you work on projects from multiple locations, you can update the local copy with changes committed to the repository from somewhere else.
- good online reference book: http://svnbook.red-bean.com/
- FAQ: http://subversion.tigris.org/faq.html#multi-merge
- most frequent work flow:
- 1. create a file, add & commit.
- 2. revise the file.
- 3. commit the changed file.
- 4. cycle back to 2.
- it’s good to commit often, but not too often.
- once or twice a day is good, or at any point where you have an important milestone.
- you can create files and directories in an svn working directory that are not under version control.
- I often create a
/trunk/data directory for writing data that I want to be local, and not saved to the repository.
- to see a verbose log of your changes, use:
- check the status of files in a directory
- this is useful for checking what files are different from the repository.
- remove files from a repository
svn remove filename
- svn will tell you how to force it to do this if it doesn’t want to.
- list differences between revisions
svn diff -r53:49 filename
filename differences between revisions 53 and 49.
- tagging a version for “release” (all one line)
svn copy /home/disk/foo/svnwork/newproj/trunk /home/disk/foo/svnwork/newproj/tags/v1.1
svn ci as usual
- the v1.1 directory will be established.
- add keywords to your file that are dynamically updated each time you commit a file.
- add a commented line (using a character appropriate for the file type; e.g. # for python) for each keyword you wish to add.
- keywords are surrounded by $ on both sides, with no spaces.
- currently available keywords are: Date, Author, Revision, and Id; the last is a summary of the first three.
- you must enable permission to use keywords on the file as follows:
svn propset svn:keywords “Date Author Revision Id” filname
- here’s an example from one of my .f90 files. first, the initial setup:
and then after committing, the keywords are expanded automatically:
! $Date: 2008–02–25 16:47:16 −0800 (Mon, 25 Feb 2008) $
! $Revision: 36 $
! $Author: hakim $
! $Id: O3DATA.f90 36 2008–02–26 00:47:16Z hakim $
how to remove a file from the repo without deleting the local copy:
- How to rescue a repository reporting the dreaded DB_VERSION_MISMATCH error:
- svnadmin recover <repository>
- how to add a directory without recursive adding it’s contents:
svn add - -depth=empty directory_name
svn rm - -keep-local filename
Last edited: 7 July 2015