Main /SVNTutorial

This tutorial helps you use svn from the command line, aka, the way God intended.

All kidding aside, this is a breeze for learning how to quickly use svn on a linux or Mac system. This saves you from having to run a Windows VMWare instance with shared directories to access TortoiseSVN. Yes, Diyang, I'm looking at you here!!. ;)

Quick reference

svn co [repository]Checkout
svn ci -m "message"Checkin
svn statusStatus of files in your directory

Make sure you have an SVN client installed

On the mac, pull up X11, or a terminal. You can access the terminal by Applications->Utilities->Terminal on a Mac. KDE users on linux, try konsole or any bash prompt. I usually put the Terminal on a speed-dial command so I can start one at any time.

 macphee:~ sprinkle$ which svn
 /usr/bin/svn
 macphee:~ sprinkle$ 

If you don't have svn installed:

Checking out a repository/directory

Go to (or make) a directory where you want to store a local copy of files.

 macphee:~ sprinkle$ cd ~
 macphee:~ sprinkle$ mkdir svn-tutorial
 macphee:~ sprinkle$ cd svn-tutorial/

Checkouts are very easy.

 macphee:svn-tutorial sprinkle$ svn co http://bracton.ece.arizona.edu/svn/test
 A    test/trunk
 A    test/trunk/adduser.sh
 A    test/trunk/README
 A    test/branches
 A    test/tags
 Checked out revision 8.

Let's see what we have:

 macphee:svn-tutorial sprinkle$ ls
 test
 macphee:svn-tutorial sprinkle$ cd test
 macphee:test sprinkle$ ls
 branches	tags		trunk
 macphee:test sprinkle$ cd trunk/
 macphee:trunk sprinkle$ ls
 README		adduser.sh
 macphee:trunk sprinkle$ 

Check out to a different directory

 svn co http://bracton.ece.arizona.edu/svn/test dirname

Check out using a different username

 svn co --username myname http://bracton.ece.arizona.edu/svn/test

The svn RCS philosophy

You can basically call SVN a file-based email system, where you can have copies of your email anywhere you want.

The files on your machine will not automatically update themselves. You have to fetch the latest version. The gold-standard files are always on the server. The only way to know whether you have the latest version is to get the latest version.

 svn up

This gets you whatever the latest version is, and shows you what files you got.

Always do svn up before editing any files. This is common sense, the same way you think of email: always get an update (i.e., press 'Send/Receive') before you make changes, or make new files.

Committing files

After you've edited files, you must commit them back to the repository. This is like sending an email to your friends to replace the versions of the files on their local machines, with the files you are currently sending out. However, you don't spam your friends every time you make an update. This should underscore why it is important to do updates before you commit anything.

Simple commit:

 svn ci -m "a message that explains what changes I just made"

This will commit all files that are currently modified, recursively. To find out the files that are changed before committing, do

 svn status

Merging results

If someone changed the same file you did, SVN gives you a little grief, because you didn't update your files before editing, or in between your update and commit, someone else committed a new version.

If you didn't change the same lines, SVN will probably do the merge automatically. Just do another svn up and you'll be golden.

If you did change the same lines, you will see something like

 <<<<<<<<<<
  Old lines
  Old lines 2
 >>>>>>>>>>
  New Lines
  New lines 2

In your file. Choose the ones you want to keep, do an svn up, and then an svn ci.