Svn

From Iphone
Jump to: navigation, search

When more than one person is working on a project -- and even if there aren't, it's still a good idea -- it's critical to use some form of source versioning tool. I recommend subversion (svn) as solid, simple to use and free.


There are GUI svn clients -- some free -- but I don't know much about them. This is a quick intro to command-line svn, and a pointer to some SVN GUI clients.


Before doing anything, you should download the PDF reference book for SVN. You don't need to read the whole thing, but it's a great reference, and you *SHOULD* read and understand the first chapter, as it's key to using svn. Chapter 1 is also available on the web.


Brief intro to the command-line.

  • The terminal command-line prompt is "$".
    • When these instructions tell you to type something to the command line, the instructions will begin with "$", but you don't type the "$", just what follows.
  • Similarly, "#" is the "ignore everything after this" comment character.
    • Hence, you don't have to type "#" or anything that follows, that's just there as a comment to let you know what a particular command does. Here's an example session you can try in the terminal:
      • Terminal.app can be found in Applications -> Utilities. When you launch it, you will get the command-line prompt after a few seconds.
 $ pwd  # print (display) the working [current] directory.
 $ ls   # list the files in the current directory.
  This page is Under Development.
  It contains rough notes that may be useful, but has not been edited to its final form.
  If you have questions, contact your developer.


Brief intro to svn via the command line

  • First, get yourself a subversion account.
    • If you use the same account name that you use for OS-X, it will simplify things. So, for you, it'd be the name of your "home" folder in the /Users directory.
    • I.e., mine is "olie", so I use that as my svn account name, too.

Getting a new project (Checkout)

Exactly-once per project, you need to get the initial project off of svn (we'll assume it's something a developer (me) put there; the case where you upload a brand-new project to svn will be covered at a later time.)

  • In finder, create a folder that will hold your projects.
    • NOTE: When we check-out the project, this folder will hold ANOTHER directory that will contain the specific project.
    • Hence, this folder that you create is the parent-folder that holds all your projects.
  • Open a terminal window. In it, type:
 $ cd     # do NOT press return.
  • Drag your newly created folder to the terminal window.
    • This will result in the folder's path being pasted into the command line, simplifying typing and eliminating errors.
    • Now press return.
    • The "cd" command is "change directory", so you will now be in the folder just created.
  • Continuing in terminal, type:
 $ svn co XXX YYY  # get project at XXX and put it in folder YYY
  • Substitute the svn-repository URL for XXX
  • Substitute the name of the sub-folder into which you want to place the project for YYY
  • The svn command "co" means "checkout"; you are checking out the project for work.

Getting the latest version of a project (update)

  • In terminal, cd to the directory containing the project that you'd like to update.
    • You can use the "cd" -> drag-a-folder -> press-RETURN technique described in the checkout section, if you like.
  • Continue with these commands:
 $ svn status -u  # display the files that svn will update
  • A list of files will be output.
    • "*" indicates files which will be updated from the repository.
    • "M" means that your local copy has been modified from what's in the repository.
    • "?" means that svn is not currently working with these files that exist in your local copy.
 $ svn update  # update your project with the repository.
  • A list of updated files will be output.
    • "A" indicates files added.
    • "D" indicates files deleted (because they were deleted in the repository.)
    • "U" indicates files that received updated changes.
    • "G" indicates files that had overlapping changes in the repository AND in your working copy, but svn successfully merged those changes.
    • "C" indicates files that had overlapping changes in the repository AND in your working copy, but svn WAS UNABLE to merge the changes, and there were conflicts.
      • YOU MUST review the files with conflicts and manually alter them to resolve the conflicts before you can check them in, again. (See <Resolving Conflicts>)

Resolving conflicts (resolve)

In the event that you change a bit of code, and someone else has changed the same bit of code and put their change in the repository, and svn can't figure out how to merge both of your changes, you will get a "conflict", indicated by a status "C" when you update.

Inside the conflicted code, you will have something that looks like this:

 <<<<<<<< .mine
 
 // conflicting comment line added here
 
 ========
 
 // Comment line added.
 
 >>>>>>>> .r123

This shows a case where, in your local copy, you added the line

 // conflicting comment line added here

However, in the repository, as of revision 123, someone else had already added the line

 // Comment line added.

in the same place, and svn isn't sure which one it should use.

When you encounter a conflict:

  • Search the file for "<<<", which is unlikely to exist anywhere else in the file.
  • Look at what you wrote, and what the other person wrote, and figure out what the correct text should look like.
  • Edit the file to the correct text.
  • Enter this svn command:
 $ svn resolved XXX  # substitute the name of the edited file for XXX

Checking-in your changes

(Coming soon!)

Subversion GUI clients

...About which I know nothing, but some of which might be good (how's THAT for a recommendation?!):

More: