SVN is the next big productivity and collaboration tool to grace the internet. Subversion is the wiki of development, allowing you to track changes, switch to older versions of your project and work as part of a team. Using SVN is a fairly easy process that can be accomplished with extreme ease through the command line.
Assuming you have access to a subversion repository (such as a project on wp-plugins.org like I do), here’s how you can go about using svn to track changes and work collaboratively.
Open Terminal.app. We’re going to be using the command line. If you don’t normally go near the Terminal, don’t panic. Using svn through the command line is easier than it seems.
Check it out
Before we start developing and updating our application, we need to grab a copy of it first. We do this through the checkout command. Checkout, as the name implies, picks up a copy of your application from the repository and downloads it to a location you specify. The checkout command requires to pieces of information. The location of the subversion repository and the location of the folder you wish to download this to. You can omit the latter argument and have subversion download to the current path. For example, if you run cd ~/project/ before using checkout, the contents of the repository will be deposited in ~/project/. Let’s do an example checkout command:
svn checkout http://svn.example.org/turfapp/ ~/projects/turf/
Every subversion command you wish to run must be preceded by svn as in the above example. Running the preceding in the Terminal will download the turfapp project (doesn’t really exist). Now, we’re ready to get to work!
Once we’ve checked out a project, we can make edits and updates to our hearts content.
Ready to Commit?
When you’re happy with the changes made, you may upload your work back to the subversion server. However, if you’re working on a collaborative project, someone may have made a change after you checked out the project. If you upload your copy, it would over-write their work. For this reason, we run the update command.
cd ~/projects/turf/ svn update
This will tell you which revision you have. If everything is fine, we’re good to upload our changes. We do this by running the commit command. With the commit command, you also need to specify a message about what changes you have made.
svn commit -m "Added the Sparkle framework"
The above assumes you’re in the correct directory. The message sent to svn would in the example would be “Added the Sparkle framework”. Make your message descriptive so anyone else (or even yourself in six months time) can tell what you’ve done fairly accurately.
Once you’ve run commit, svn uploads any files that have changed and your updates are saved.
Adding files
Straight add
If you add a file to the working directory, then run commit, you’ll find that svn doesn’t find any changes to update with. Whenever you add files to your working directory that you wish to add to the project, you need to tell svn.
svn add newfile.ext
If the file to be added is in a folder, you’ll also need to specify that:
svn add sources/newfile.h
Or if the resource you’re adding is a folder, you can just specify the path:
svn add headers/extension/
Import
The import command doesn’t require you to have a checked out copy of the project, and it allows you to import a file to the server from any location on your hard drive (whereas add is usually restricted to the working directory). For the import command, you need to know the path to the resource, and the path on the server where it should reside. For a folder, you need to specify the path on the server that the folder will take, rather than the path where it should reside as svn will upload the contents of the folder rather than the folder itself. This can be confusing at first if you’re not aware of it.
The import command will commit the changes you make, so you need to provide a message as well. The overall syntax is:
svn import -m "message about update" /Path/To/Resource/ http://svn.location.on/server/trunk/
Let’s add a file to our project:
svn import -m "Adding about xcode pdf" /Developer/AboutXcode.pdf http://svn.example.corg/turfapp/trunk/resources/
Will result in the file being uploaded to the server at http://svn.example.corg/turfapp/trunk/resources/AboutXcode.pdf.
Deleting files
Now that you can import files, deleting them should be easy. The analog to import is (surprisingly) delete. You can just pass the URL of the file on the server to delete, or you can pass a path to a file in the working directory. If you pass a URL, the change is committed and a message is required. Let’s get rid of that pdf we imported:
svn delete -m "message about deletion" http://svn.example.corg/turfapp/trunk/resources/AboutXcode.pdf
If you specify a path in the working directory and don’t send a message, the change is recorded and snchronized with the server the next time you run commit. For example:
svn delete trunk/resources/AboutXcode.pdf
In which case the change is not reflected on the server until you run:
svn commit -m "summary of changes"
Summary
SVN can be used to coordinate the development of a project. A project needs to be checked out using the svn checkout into a working directory before it can be edited. Updates are saved using the svn commit command, and files can be added using svn add or svn import, while files are removed using svn delete
Some svn commands are analogous to the standard UNIX commands; you can use ls, mkdir, cp etc. to navigate and manage your repository.
That’s it!
You can find out more about subversion at http://subversion.tigris.org. Run svn help or svn help subcommand to learn more about the svn commands.
Have fun!
8 Comments so far
Leave a commentExcellent! I have written not so long ago an entry in my blog with a similar introduction to svn on Mac OS X, but in Spanish; hope it helps!
http://kosmaczewski.net/2007/01/01/subversion-1/
http://kosmaczewski.net/2007/01/02/subversion-2/
(in Spanish) En los links aqui arriba hay una introduccion a svn para Mac OS X, similar a la de esta pagina, pero en espaƱol, espero que sea util!
recorded by Adrian on March 21, 2007 11:17 pm | Permalink
You forgot to mention a big link in subversion land.
http://svnbook.red-bean.com/
The complete and free online version of the O’Reilly Subversion book.
Oh and Google Code, sourceforge.net provide subversion access as well. But better to first fumble around a bit with a local working copy.
svnadmin create testrepo
svn checkout file:///[PATH_TO_REPO]/testrepo
Start experimenting…
XCode works well with local repositories as well. Sure, you don’t have the security of a remote backup. But a local repository is just another path on your disk. Pick it up in your regular backup and you are reasonably safe.
revealed by Jeroen Leenarts on March 21, 2007 11:20 pm | Permalink
I started using Subversion midway through a current project of mine, and now I wish I’d started sooner. I didn’t really “grok” it till I read the Pragmatic Programmer’s book on SVN http://www.pragmaticprogrammer.com/titles/svn/
One of the issues I found when starting to use Subversion midway, is that what looked relatively organised in my Xcode view turned out to be one honking big disorganised directory when you looked at it on disk.
If you’re going to be writing any more on SVN, might I suggest a tutorial on how to structure your Xcode project for better on-disk organisation (which in turn makes things easier to manage in SVN). For example, how to split up your external frameworks from your central code in SVN.
declared by Nick on March 22, 2007 8:48 am | Permalink
Ah. There it is
http://svn.wp-plugins.org/gregarious/trunk/
announced by C.J. on March 23, 2007 9:01 pm | Permalink
I’ve been setting up and blogging about subversion and XCode. My set up is very simple: just me and and a local repository. I’m still learning now to use subversion, so everything that you wwrrite is useful.
http://homepage.mac.com/bagelturf/cocoa/cocoa.html
composed by Steve Weller on March 24, 2007 3:07 pm | Permalink
Thanks Steve. The great thing about subversion is that once you’ve set up everything, you can keep working on your project as per normal; the only real change one has to implement into a workflow is running
commitonce in a while.I have been keeping an eye on your blog and you’ve got some great content. Keep it up!
written by Ankur on March 24, 2007 5:15 pm | Permalink
thats great everything is working fine.
can u tell me how can a user change his password
is it possible with admin!! (i dont think it is possible)
recorded by hemi on October 20, 2009 3:46 pm | Permalink
Sometimes a nice simple article covering the basics is just what’s needed. I’ve been ‘intending’ to start using a versioning system since a few hobby projects now. But this article was the exact little push I needed.
Now all I need is for you to write an article about test-driven development..
Thanks for the great article!
uttered by Pranab on December 8, 2009 4:36 pm | Permalink
Leave a comment