If you are a web or application developer, there will come a time (hopefully) that you will need to use subversion for your projects. While I use the command line for this – there are some GUI applications that make it easy for people to manage their files using subversion. For this documentation, I have chosen to write about RapidSVN because it runs on both Mac and PC.
ONE TIME PROCESS
- Download the RapidSVN you will use to check in and check out files at: http://www.rapidsvn.org/download/release/0.9.6/. For Mac users – download the .dmg gile. For PC users, download the .exe file
- Install the applications on your computer.
- Check out the files that you want to edit. Go to the “Repository” menu and select “checkout”.
- Enter in the URL of the repository where the files are currently located. (http://www.example.com/svn/yourfiles)
- Choose where you want these files on your to be downloaded to on your computer (destination directory)
- Use the latest revision (unless you have a reason to choose something else)
- Do not worry about “Peg Revision” – Click the “Ok” button
- You will be prompted for a user name and password – those are for the repository. Enter in the information and your files will then be downloaded to your computer.
AFTER YOU HAVE INITIALLY CHECKED OUT THE FILES AND ARE READY TO MODIFY THEM
- Make changes to the existing files as needed. Once you are done, click on the icon for “Commit Change”. (Look for the up orange arrow).
- Enter in some documentation of the change. (Ex: I changed the CSS so that the navigation now works in IE 6)
- Click the “OK” button and your changes are now made to the files in the repository.
ADD NEW FILES
- Add the new files/folders to your local (on your desktop) copy of the files.
- Within RapidSVN – Click on the bookmark you want to work with on the left side of the window. On the right side – the files for that bookmarked repository will appear. You will see all your files – old and new.
- Highlight the new files you added and click on the “Add Selected” button.
- You will be prompted for a comment (explanation). (Ex. Added new graphic files for the header)
- Check those new files in by clicking on the “Commit Change” button. Add another comment. (Ex. Checking in the new graphic files).
DELETE EXISTING FILES
*** Regardless of what happens – DO NOT DELETE CHECKED IN FILES USING YOUR OPERATING SYSTEM’ DELETE OPTIONS (move to trash, etc). If you want to delete a file from the repository – you must use SVN. If you delete the files with your OS – you will get errors which will stop all future edits until it is remedied. You might see a folder with a name of “.” do not worry about it, remove it, or try to delete it.
*** You can only delete files that have already been checked in. If you add files, do not check them in, and want to delete them – you can use the OS to delete the files.
- Within RapidSVN – Click on the bookmark you want to work with on the left side of the window. On the right side – the files for that bookmarked repository will appear.
- Highlight the file you want to delete and click on the “Delete Selected” icon. The file will still be listed until you check in your changes.
- Check in your changes by clicking on the “Commit Change” button. Add a comment. (Ex. Removed old logo file). 4. The list of files will now be updated.
Ever delete something with svn (svn del) and then realize you needed it again? You can get it back by using:
svn copy -r HEAD filenameyoudeleted.extension filenameyoudeleted.extension
- svn copy is the command to get a working copy back
- -r is short for revision. I used HEAD which will give you the latest in repository. You can specify a revision number, revision right before you committed, etc (check out svn help copy)
- filename is what you deleted, then where it goes. I usually do something like this within the folder the file was located so you do not see any paths, but if your file was in /www/files/ you would need to specify the file path to /www/files/filnameyoudeleted.extension /www/files/filnameyoudeleted.extension
Working with SVN is a lifesaver – and this tip is gold.
Because I always forget…to change the text editor that svn uses with the commit messages, just type in this command (if you use bash):
*Substitute vi for your editor of choice.
**Personally, I once was a pico/nano fan, then I moved to emacs, and now I am a vi person.
Something that confuses a lot of people when they start using subversion is the file status. (svn st) Here is a quick list of the file status codes and what they mean:
- A File was added
- C Conflicting changes
- D File was deleted
- G File was merged
- R File was replaced
- U File was updated
- ? File is not under version control (you will need to add it)
- ! File is missing (probably was deleted using the OS or some other application and not subversion)
In order to take a look at WordPress 2.5 before it was released, I used subversion to check out the latest code available using the instructions given on the WordPress site. Once WordPress 2.5 was released, I wanted to keep my sites using 2.5 and not the bleeding edge releases (2.6) so I needed to easily switch repositories from http://svn.automattic.com/wordpress/trunk/ to http://svn.automattic.com/wordpress/branches/2.5/.
I had never had to switch repositories, so it took some reading to figure it out. For future reference, the following command works when used in the directory you have the checked out files in: “svn switch http://newrepos.com .” For my example, I ran the command: “svn switch http://svn.automattic.com/wordpress/branches/2.5/ .”
Anyone who uses subversion will need this sooner or later. Change directories to the root directory and run:
find . -name .svn -print0 | xargs -0 rm -rf. Bingo…all .svn directories are gone and you can start fresh!
To address my increasing backup needs as well as my need for more FireWire and USB ports, I decided to buy a miniStack (500GB). I own a Mac Mini and so the miniStack seemed like the perfect solution. Now comes my friendly reminder to all those reading that do not back up…back it up! On another note, I also recently started using SVN for all my business projects (thanks Demitrious) which is backed up offsite. Back up!
[tags]mini stack, SVN, backup[/tags]