(1) Create Subversion repository parent in /usr/local/svn and a local repository named project1 in /usr/local/svn/project1.
$ sudo mkdir /usr/local/svn
$ sudo svnadmin create /usr/local/svn/project1
(2) Configure Apache so it has read/write access to the repository. Apache runs as user www.
$ sudo chown -R www /usr/local/svn
(3) Configure Apache to support SVN by editing httpd.conf
$ sudo vi /etc/apache2/httpd.conf
Add to LoadModule section
LoadModule dav_svn_module libexec/apache2/mod_dav_svn.so
At end of the file, make sure that include files reads like
Include /private/etc/apache2/other/*.conf
4) Create httpd-svn.conf file
$ sudo vi /etc/apache2/other/httpd-svn.conf
My file which requires all users to authenticate
DAV svn
SVNParentPath /usr/local/svn
# how to authenticate a user
AuthType Basic
AuthName “Subversion repository”
AuthUserFile /etc/apache2/subversion.auth
# only authenticated users may access the repository
Require valid-user
(5) Configure Authentication by creating an password for user shawnb
$ sudo htpasswd -cm /etc/apache2/subversion.auth asif
The passwords are essentially passed in plain text over the connection. The recommendation is to use HTTPS, but I am using this on an internal network. Maybe later.
(6) Stop and start Apache server using apachectl or by un-checking and checking the Web Sharing checkbox in System Preferences > Sharing.
To access SVN, the URL is http://localhost/svn/project1. The configuration is using SVN ParentPath configuration which means that you can have multiple repositories in /usr/local/svn (e.g. project1, project2, etc). Note: project1 is just a dummy name; please replace with
(7) Finally, add the tags/branches/trunk directories to your SVN repository ‘project1?
Now we have our svn area set up, lets imagine we want to create a repository for a project, perhaps one we’ve already been working on before (although this will work even if you haven’t yet started).
First we want to create a sample set of folders which can be used time and time again to set up the default folder structure of the SVN repository. Choose a location on your system – I’ve done it in /Library/WebServer/Documents, and create the folder svn_default and within that /trunk, /branches and /tags. You can do this from terminal using the following commands:
sudo mkdir /Library/WebServer/Documents/svn_default
sudo mkdir /Library/WebServer/Documents/svn_default/trunk
sudo mkdir /Library/WebServer/Documents/svn_default/branches
sudo mkdir /Library/WebServer/Documents/svn_default/tags
sudo chown -R www /usr/local/svn
svn import -m “initial import” /Library/WebServer/Documents/svn_default http://localhost/svn/project1
Adding /Library/WebServer/Documents/svn_default/trunk
Adding /Library/WebServer/Documents/svn_default/branches
Adding /Library/WebServer/Documents/svn_default/tags
Committed revision 1.
You should now see all the files adding into the SVN repositiory, and at http://localhost/svn/appname you should be able to click on the Trunk link and see the files.
Now all the files are in the SVN, you need to check them out for the first time in order to start working on them.If you, like me, want to work on the same folder as the one you just uploaded from, you will need to remove that folder before continuing.
sudo rm -r /Library/WebServer/Documents/appname
Then go to the directory above the one you want to work with – so instead of appname (which should no longer be in Documents anyway), go to Documents.
cd /Library/WebServer/Documents
Then checkout the files
svn checkout http://localhost/svn/appname/trunk appname
Now you should see the files in the appname folder. Well done, you can now make changes to files and use the commands listed below to add the changes and retrieve them from the SVN system.
Working with SVN repositories on OS X
Now you have a working repository you can use various commands to save and retrieve code changes.
You first must always navigate to the folder you set up in terminal, so following the above example it would be
cd /Library/WebServer/Documents/appname
Get the latest code
When you start work you should update to get any changes made, if more than one person is making changes to the code.
cd /Library/WebServer/Documents/appname
svn update
Find differences you made since the last commit
After updating, you might change some files, to find out what files you changed run
cd /Library/WebServer/Documents/appname
svn status
To find out exact changes run
cd /Library/WebServer/Documents/appname
svn diff
Set a file back to how it was before
You’ve changed a file, but haven’t commited, and you don’t like what you’ve done. You can easily go back to the last committed copy by typing the following:
cd /Library/WebServer/Documents/appname
svn revert path/to/file.php
where path/to/file is the path from but not including appname. e.g. if I made an error in appname/path/to/file.php I would use the above path
Saving changes
After making all your changes you can save them back into the repository with the following command:
cd /Library/WebServer/Documents/appname
svn commit -m “Describe the changes you made”
Adding a group of new files
When you add new files to a project they won’t automatically get added by Subversion. You can either add them one by one using
svn add filename_or_dirname
or try
svn –force add .
Removing files
To remove a file or folder from your project, don’t just delete it from your local file system. Instead do this:
svn delete filename_or_dirname
That marks them for deletion and removes it from the local file system, when you next commit, they will be deleted from the svn repository:
svn commit -m “removing files”
Tagging a version of your code
If you are happy with a version of your code and want to take a snapshot to make it easier to roll back should problems arise with the next version, you can create a copy with a tag. Remember the tags folder we created, thats a good place to put these tagged versions. Users can then download them from here, and not worry about small changes you may have made since.
To do this:
svn copy http://localhost/svn/appname/trunk http://localhost/svn/appname/tags/release-1.0 -m “Tagging the 1.0 release of the ‘appname’ project.”
Creating a Branch
If you want to make a branch to continue working on a project, perhaps in a different way to before, a branch should be created.
To create a branch
svn copy http://localhost/svn/appname/trunk http://localhost/svn/appname/branches/branch1 -m “new branch”