Subversion With Mac OS X Tutorial

Tags: , , ,
Posted 21. September 2006.

Updated: June 2009

Subversion is a version control system that allows you to work with other people on a project and switch back easily to every version ever made. It can be used for all kinds of projects like application source code, web sites, even images or just simple text documents. Once you have it all set up and followed all the steps described below, it is easy to handle and a very useful thing – not just for computer geeks.

About This Tuturial

This tutorial explains the basics from installing subversion and getting started to working with other people on the same project. It is written primarly for Mac OS X users, but since Subversion itself works the same on all platforms, most of this tutorial should apply to Linux or Windows users, too.

The Concept of Subversion

Subversion works by setting up a central repository on a server or local computer that every user connects to and downloads a personal working copy from. When changes are made to the working copy, they can be uploaded to the repository. If these changes conflict with changes other people may have uploaded since the last time you updated your working copy, subversion tries to merge these files and solve the conflicts.

Downloading and Installing Subversion

I recommend downloading the Subversion Mac OS X package from Collabnet

Download and run the installer. Note that Subversion itself doesn't feature a graphical user interface, so you won't find any new files in your application directory after installation. Instead it installs some command line commands into the directory /opt/subversion/bin* on your hard drive. *Note: For other Subversion packages this path is usually /usr/local/bin.

To be able to call the Subversion commands from every directory, you must add it to your path. If you don't know what that means, don't worry. Just follow the instructions.

Open the Terminal application. It can be found in the /Applications/Utilities folder. Whenever you see below a line starting with a dollar sign, you should type the text after the dollar sign in your terminal and hit return.

Start by creating a new text file called '.bash_profile', i.e. with the command line text editor pico:

$ pico .bash_profile

Add the following line to the text file:

export PATH=/opt/subversion/bin/:$PATH

Now hit Control-X, then confirm saving the file with 'y', followed by return.

You have just added Subversions's location to your path. Let Terminal read this file to know the path has changed (there's an empty space between the dots):

$ . .bash_profile

Creating a Sample Subversion Project

First we will need to set up a Subversion repository on our local computer. That is the place to store all versions of our project. Now create your repository like this:

$ svnadmin create SVNrep

This will create a repository named 'SVNrep' in your your home directory, although svnadmin won't give you any feedback. If you don't trust me on this, you can check the existence of this folder by typing 'ls' in the terminal or looking for it in the Finder.

Next we create our sample project. Create a new folder and an empty file named 'test.txt' inside this folder:

$ mkdir test
$ touch test/test.txt

Let's import this project into the repository. Type in you terminal, by replacing 'sara' with your own user name:

$ svn import test file:///Users/sara/SVNrep/test -m "Initial import"

This will output:

Adding test.txt
Committed revision 1.

We have just imported the folder 'test' into the repository 'SVNrep'. Each version in the repository is called a "revision" and is identified by a unique number. Always provide a short message ('-m') of the changes you made to the repository like we just did!

Retrieving Files From Subversion

Now we get a copy to work on from the repository. This process is called "check out":

$ svn checkout file:///Users/your_user_name/SVNrep/test test-copy

The output will show all files added ('A') to our working copy:

A test-copy/test.txt
Checked out revision 1.

Change into the working copy directory by typing:

$ cd test-copy

Next check the content of our working copy in the terminal:

$ ls -a1

This will output the directory including hidden files:

.
..
.svn
test.txt

Note the hidden directory '.svn'. This holds some subversion info like the name of the repository, so you don't have to type that in the future. If you would like a copy of your repository without this hidden directory in every folder, you have to export a copy:

$ svn export file:///Users/your_user_name/SVNrep/test test-copy

This copy is now safe to deploy on the web. It is not a working copy though, so you can't commit changes back to the repository from this folder.

Time For Changes

It is time to make some changes to our file and save it back to the repository. Open 'test.txt' from the working copy with your favourite text editor and type "Hello world" or whatever you are up to, then save the file.

You can then query Subversion to find out the differences between the repository and your copy:

$ svn status

This will state that our file has been modified ('M'):

M test.txt

Now we want to update the repository with the changes we made. This process is called "committing":

$ svn commit -m "Added some text"

This will output:

Sending test.txt
Transmitting file data .
Committed revision 2.

Dealing With All These Versions

Let's assume, that someone else working on your project made changes to the repository. You will want to update your local working copy to incorporate the changes:

$ svn update

Because in our example nobody else made changes to the repository, this will do nothing and output:

At revision 2.

To list all revisions in the repository, type:

$ svn log

This will output a list of all revisions with it's messages:

------------------------------------------------------------------------
r2 | sara | 2006-10-08 16:41:46 +0200 (Sun, 08 Oct 2006) | 1 line
Added some text
------------------------------------------------------------------------
r1 | sara | 2006-10-08 16:10:36 +0200 (Sun, 08 Oct 2006) | 1 line
Initial import
------------------------------------------------------------------------

If you would like to see the exact differing lines to a specific revision, i.e. revision 1, just type:

$ svn diff -r 1

The output states that the line "Hello world" has been added ("+"):

Index: test.txt ===================================================================
--- test.txt (revision 1)
+++ test.txt (working copy)
@@ -0,0 +1 @@
+Hello world

Maybe you would then rather like to switch back to an older revision:

$ svn update -r 1

This will update ('U') your copy back to revision 1 and output:

U test.txt
Updated to revision 1.

Note that all commands are used on the whole current working directory. You could also provide a single filename for each of these commands, i.e. 'svn update test.txt'.

Renaming, Adding And Deleting Files From The Repository

Sometimes you may add new files to your working copy.

$ touch test2.txt

They will not be included in the repository though, unless you manually add them to the repository:

$ svn add test2.txt
$ svn commit -m "added new file"

If you later would like to remove a file from the repository, type likewise:

$ svn delete test2.txt
$ svn commit -m "deleted file"

Note that you should never delete or rename files from your working copy without Subversion knowing. You can modify inside your files as much as you like. But if you just rename files or move them to another folder, Subversion will loose track of them. Always use 'svn' commands for those operations.

This is how you move a file accordingly:

$ svn move oldfilename newfilename
$ svn commit -m "moved file"

All of these commands will not only affect the repository, but your working copy as well. So you should never have to delete or rename a file with your Finder.

If you are working alone on a project, this is it! Well, basicly. The next chapter will explain dealing with multiple users.

Working With Other People

To act as if someone else was working on your project, you could now check out a second working copy named i.e. 'test-copy2' into your home directory and make some more changes to it. Then commit it to the repository following the steps from above.

Now think of a possible conflict: two people have downloaded their working copy and started working on the same file. When Sara commits her files before Michael does, Michael will get an error message when committing because his copy is not up to date any more:

$ svn commit -m "Some change by Michael"
Sending test.txt
svn: Commit failed (details follow):
svn: Out of date: '/test/test.txt' in transaction '3-1'

Michael will then first have to update his working copy by typing 'svn update'. This will merge Sara's earlier changes into Michael's working copy, line by line.

Michael can now commit the merged copy to the repository. In some rare cases however, there my be a conflict that Subversion cannot solve itself. It will then create three files in Michael's working copy:

test.txt.mine
test.txt.r2
test.txt.r3

Michael now has to manually put the pieces together in the file 'test.txt', deciding which changes to keep. Only when this is made and the three extra files are deleted, Subversion will allow Michael to commit his files.

Now go play around with it to get used to it. Of course there is more to Subversion. You could type "svn help" in the terminal to list all commands or read the freely available SVNbook at http://svnbook.red-bean.com

Graphical User Interfaces

Many people don't like working with the terminal. They find it complicated to remember the text commands, as opposed to clicking on buttons in applications. There is a couple of free or commercial apps available on the internet, that provide a graphical user interface for Subversion commands. I think it's best practice to learn Subversion from the terminal first, before you use a graphical client, to understand the way subversion works better.

A nice and free GUI for Mac OS X is svnX. To manage your working copies from the same application that you write your code with, the text editor TextMate is a good choice. TextMate includes a Subversion bundle that allows you to easily invoke most Subversion commands from the menu. Only once for setting up the repository and checking out the first working copy, you will have to use the terminal. After that, just press Shift-Control-A to open the Subversion bundle menu.

SubscribeSubscribe to this Feed
del.icio.usSocial bookmark

Questions or comments? [54]

  1. Alpha said 802 days ago:

    Collection of AppleScripts for Finder (made by me) can be also useful to make the most frequent operations easier.

  2. Charles Lloyd said 789 days ago:

    This was the best svn quick-start tutorial I found on the web (especially since I’m a MacOSX user). I glanced at a few other articles and didn’t see clear instructions for geting up and running like I found here. An article this well-written is a rare find on the net. I was up and running with my new svn repository in a matter of five minutes.

  3. Raj said 529 days ago:

    Excellent tutorial on the basics. Thanks! Got me up to speed enough to get a simple repository going.

    (However, in trying to print this from different computers, the right margin cuts off the text. You might want to adjust your print css to increase the right margin a bit.)

    Thanks again!

  4. Niko said 521 days ago:

    Printing should work now! Tested with Firefox.

  5. Silverhammer said 519 days ago:

    Echoing the previous comments, this is by far the best quickstart I’ve been able to find for running SVN on Mac OS X. Thank you very much.

  6. Ryan said 509 days ago:

    I’d just like to say thank you for writing this straight forward tutorial. This is the first tutorial that I have came across that makes perfect sense and allowed me to get started!

  7. AJ said 495 days ago:

    Like others here I looked at a bundle of other ‘quick-start’ tutorials but found none that really seemed to explain subversion as well as you have done here.

    I am now ready to roll up my sleeves and begin playing around with subversion – thanks!

  8. Erinc said 489 days ago:

    Your tutorial helped me a lot too. Thank you for your time.

  9. Alan Bristow said 466 days ago:

    Thanks lots for this. On the GUI front, I am looking at http://zigzig.com/

  10. Olly said 452 days ago:

    Hi, Can you help me?

    I’ve changed the .bash_profile file as you have said. It now looks like this:
    ————————-
    export PATH=/user/local/bin:$PATH

    # Setting PATH for MacPython 2.5 # The orginal version is saved in .bash_profile.pysave
    PATH=”/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}”
    export PATH
    ————————-

    But the svnadmin is returning a ‘command not found’ message. I’m guessing this might have something to do with the Python path thing (I played around with Python a while back but never really use it). I’ve tried your line of code at the start and end of the file, but not luck.

    Any assistance much appreciated.

  11. Niko said 451 days ago:

    Hi Olly,

    your .bash_profile should work. Are you sure you installed svn correctly? Try calling it directly with it’s full path: “/usr/local/bin/svnadmin”

    If that doesn’t work, you can search your hard disk like this:
    “find / -name svnadmin”

  12. Olly said 450 days ago:

    Here is what I get when I type in it’s full path.

    Le-Big-Mac:~ Olly$ /usr/local/bin/svnadmin
    Type ‘svnadmin help’ for usage.
    Le-Big-Mac:~ Olly$ svnadmin help
    -bash: svnadmin: command not found
    Le-Big-Mac:~ Olly$

    Sorry to bother you, but can you advise what this means? I’m new to *nix and Subversion and really need to learn it quick!

    Many thanks for any assistance.

  13. Niko said 449 days ago:

    I found it, it’s really simple: a typo in your .bash_profile

    Make sure you change the faulty line:

    export PATH=/user/local/bin:$PATH

    to:

    export PATH=/usr/local/bin:$PATH

    That should be it!

  14. Olly said 448 days ago:

    Groovy! Thanks for your help.

  15. Nick said 431 days ago:

    How do I uninstall this client?

  16. Niko said 428 days ago:

    Nick: most unix tools don’t include an uninstall script by default. In this case look inside the package and see what files are included, then delete by hand.

    Or just delete every file in /usr/local/bin and /usr/local/share/man that starts with “svn”. It’s not necessary though. Subversion uses only very little space on your hard disk and does not interfere with your system.

  17. lobsterman said 414 days ago:

    i have been a newbie to command line stuff and i have been struggling with working through the begining of the instructions – at the ..bash_profile i kept getting

    -bash: ..bash_profile: command not found

    until i realized rather by accident that there was meant to be a space between the two dots. a note in the instructions to that would have been helpful, other than that things work like a gem.

    thanks, ciao,

  18. Quiz said 413 days ago:

    Very, very good tutorial. Thank you very much.

  19. Niko said 413 days ago:

    Thanks for all your friendly comments! It’s good to see that this tutorial is helpful for so many people.

  20. Calvin said 412 days ago:

    Oh man, I just spent an hour trying to set my path. This page was the first one that said to type the . .bash_profile. Worked like a charm after that. Thanks a lot!

  21. Carlos Le Mare said 400 days ago:

    It work!!!… I having issues trying to updates files in my repository SCPlugin with authentication… but working with command line reveals the problem… for some reason (I don’t know why yet) my subversion is trying to use my username in mac os x to upload the files, but I use another username in the repository. Anybody knows how to change the default username? (mac os x 10.4.11)

  22. Anthony said 392 days ago:

    Thanks – I’ve been meaning to get to grips with svn for ages, and it’s not too difficult after all!

  23. TrainMe said 392 days ago:

    How i can commit just one file?

  24. Niko said 392 days ago:

    Carlos: Yes, that’s standard behaviour for most shell commands. You should be able to provide your username in the the subversion configuration file or use “-l username” directly when connecting from command line.

    Trainme: to commit just one file, just specify the file name!

    svn commit myfilename -m “Just one file!”

  25. edouard said 325 days ago:

    thank’s for this tutorial … it has been very helpful since svnX seems not to work with mac osX.5 … at least the terminal performs quite well the same ..
    ^^

    ed.

  26. freefone said 324 days ago:

    excellent. excellent. thank you!!
    was wondering if someone here can help: i’d like to keep both a local and remote repository. is there a way to commit to a local repository and then replicate the local server copy to a remote location. thx.

  27. Niko said 319 days ago:

    I don’t see how duplicating a repository would be useful, if not even harmful – unless it’s for reasons of backup. In that case simply copy the repository folder to the remote location via ftp or rsync…

  28. PXD said 313 days ago:

    Excellent article, nice and easy :)

  29. Wolfgang said 259 days ago:

    Thank you very much for this tutorial. Your work is very much appreciated!

  30. Beltonaki said 232 days ago:

    This tutorial is still very nice indeed. Thank you for making subversion an easy start! :)

  31. Raf said 227 days ago:

    Great tutorial, thanks a lot :)

  32. Patrick said 201 days ago:

    Thanks for the tutorial, it was very helpful.

    I’m looking at Xcode 3.1 and it seems that all of most of the commands in the tutorial are duplicated in the SCM menu (add, commit, etc.). Is that the case? If so, can I skip learning the terminal commands (although of course learning the concepts) and rely on the Xcode 3.1 SCM menu?

  33. RP said 149 days ago:

    I have an external drive called ‘SVN’ that I’d like to use as my repository (feeling it’s best to have it somewhere other than my local machine), but I don’t know how to set this drive as my repository. Can anyone help with the proper commands? Thanks.

  34. Christelle said 128 days ago:

    Excellent tutorial. Everything works like a charm, I love it!

  35. Rocco said 94 days ago:

    I would like to add my voice to the chorus of thankful people. Your tutorial is exactly what I was looking for to get started. Thanks!

  36. Arthur said 93 days ago:

    Sorry, but after I`ve typed this “svn status” I saw this line “svn: warning: ‘.’ is not a working copy”
    why?! (sorry for my English) and how can I correct it?

  37. Niko said 93 days ago:

    Arthur: Make sure are in the directory of your working copy, before calling svn commands: ‘cd test-copy’

  38. Emmanuel Seynaeve said 92 days ago:

    Thanks for the great tutorial. Really the best one out there!

  39. Per André Rønsen said 85 days ago:

    Thanks, great help!

  40. Moses Hall said 73 days ago:

    I think it would be helpful to potential downloaders to mention that installer Subversion-1.6.1.zip is Intel-only. The installer did not check the machine architecture or give any warnings, it just installed useless Intel binaries on my PowerPC Mac. Any chance of a universal version?

  41. tb said 73 days ago:

    … second the last comment :-(
    Warning would be nice, what the best way to uninstall it now? Will this work or is there more files scattered throughout the system:

    rm /usr/local/bin/svn*

  42. tb said 73 days ago:

    … this works fine:

    http://subversion.tigris.org/getting.html#osx

    http://downloads.open.collab.net/binaries.html

  43. Niko said 71 days ago:

    Sorry about the intel-only version. I will try to provide a universal package within the next few days. For now, PPC users are encouraged to download from open.collab.net. (See comment above)

    PS: You don’t have to remove the intel version before installing the universal package, as the files will be overwritten.

  44. Scott said 58 days ago:

    This is a great tutorial. The SVN book is good, but it’s nice to have this summary all on one page. Thanks so much.

  45. Damien McKenna said 50 days ago:

    Good article, very informative, and timely given that you wrote it around SVN 1.6. FYI the cross-platform GUI tool SmartSVN (smartsvn.com) was also updated to work with SVN 1.6, and it’s a really good GUI tool.

  46. Jeremy Whitlock said 49 days ago:

    Nice article but you might want to reconsider the binary you’re linking to. Yes, I know it appears to be one you’re maintaining but there is another that is much more featureful located here:

    http://tinyurl.com/svn-osx

    It works on Tiger+, all 4 supported OS X CPU architectures (ppc, i386, ppc64 and x86_64), it includes all language bindings (Java, Perl, Python and Ruby) and includes the Apache modules. Oh…and svnserve is built with SASL support. Not trying be a pain but it might save you some time maintaining it yourself.

  47. Niko said 43 days ago:

    OK… I removed the download link to my package from the article and do suggest downloading from Collabnet.

    The goal was to maintain a smaller package that includes only the files necessary for basic Subversion usage, but it doesn’t really make sense spending the time maintaining a package, just to save a few megabytes hard disk space.

  48. Le Thanh Duc Mr said 36 days ago:

    Really helpful.
    Deeply appreciate for your work

  49. Brendan Wood said 36 days ago:

    Thanks for the tutorial! I’ve installed SCPlugin and it works great, but there were some hiccups. SCPlugin allows you to control Subversion from contextual menus in the Finder, making life much easier. But if you’re running Leopard, make sure you disable the Finder’s icon preview option (View —> Show View Options) for any folders that contain files linked to a repository…it screws up SCPlugin’s “badges” that indicate the status of files.

  50. Patrick said 24 days ago:

    I just found this tutorial. It is very well done but I am having problems.
    Whenever I type in . .bash_profile I get a command not found message, and I am making sure that I include the space. Can you help? it would be much appreciated.

  51. Niko said 22 days ago:

    Patrick: make sure 1) the file .bash_profile exists in your home directory, 2) your working directory is your home directory when typing “. .bash_profile”

    Also check if the file’s content is correct, see article above!

  52. Domenico said 19 days ago:

    I was experiencing troubles with the installation (always getting command not found) and at last, reading and re-reading their documentation, I realized that the guys at collabnet moved all the stuff into /opt/subversion in place of /usr/local/bin. Check their Readme file. I thought it might be convenient you to know it. All the best.

  53. Niko said 18 days ago:

    Domenico: thanks for your comment. I have updated the article.

    The path to the Subversion binaries from the Collabnet package is /opt/subversion/bin

    Sorry for everyone who has experienced trouble with this.

  54. thomas said 17 days ago:

    Question,
    I would like to work with a friend of mine on a java project (Eclipse).
    The plan is to set up my computer (Mac Pro) as a server (Apache), everything is supposed to go through my computer.
    Is there a chance to get some help how to do this.
    Thank you a lot

Textile Help