A Guided Tour of Subversion (SVN)

[article]

working copy to get Bob's changes.

### Command Line

cd \temp\hanoi

svn update

### Tortoise SVN

Right Click the "\temp\hanoi" folder-> SVN Update...

In both cases, you will be given overview of what was updated.

The last scenario, which we will go through is branching and merging. Let's assume now, that Bob now has to do some performance optimization of the Counter class, which lasts long and therefore should be done in branch. Firstly, he creates the branch:

### Command Line

svn copy localhost/repos/sandbox/Hanoi/trunk/ localhost/repos/sandbox/Hanoi/branches/performance/ -m "Creating the performance branch"

### Tortoise SVN

Select the Hanoi/trunk folder in the Tortoise Repo-browser -> Right Click -> Copy to... -> Change the URL to http: // localhost/repos/sandbox/Hanoi/branches/performance/ -> OK -> Enter the commit message -> OK

Now the branch is ready and we need a working copy to modify. We can of course checkout the new working copy out of branch, but it is easier to switch the existing WC into branch. Switching has the advantage that it preserves the local modifications (if any). Therefore we can start working on some task and afterwards decide, that this requires branch and switch into the branch together with the changes.

### Command Line

cd \temp\bob\hanoi

svn switch  localhost/repos/sandbox/Hanoi/branches/performance/

The command shows all the changes made to the working copy. To verify, that we are really in branch, we can use

svn info

### Tortoise SVN

Right Click on \temp\bob\hanoi -> TortoiseSVN  -> Switch... -> Change the URL to localhost/repos/sandbox/Hanoi/branches/performance/ -> OK

The actual changes to Counter.java class are in the folder 3 in sources zip file - you can copy it into the working copy. Of course, this change is far too trivial to be done in branch, but it's good enough as a sample. Now Bob commits the changes and switches his working copy back to trunk:

### Command Line

svn commit -m "Counter optimized"

svn switch localhost/repos/sandbox/Hanoi/trunk/

Notice, that the Counter.java file was updated back to it's trunk content

### Tortoise SVN

Right Click on \temp\bob\hanoi -> TortoiseSVN  -> Switch... -> Change the URL to localhost/repos/sandbox/Hanoi/branches/trunk/ -> OK

The last operation to finish the performance optimization is merging the changes back to trunk. This has two steps - first we merge the changes from branch into the trunk working copy and after verifying the result (and merging possible conflicts) we commit the result into the repository.

### Command Line

Firstly, we need to determine revision since which we want to merge the changes - in our case it's the revision in which the branch was created (you can use e.g. svn log command to discover the revision number). In my case, it's revision 5:

svn merge -r 5:HEAD http:// localhost/repos/sandbox/Hanoi/branches/performance/ --dry-run

Firstly we perform just the dry run, which prints all the information, but does not modify any files - we us it to verify correctness of the arguments. After checking the result, we can perform the actual merge:

svn merge -r 5:HEAD localhost/repos/sandbox/Hanoi/branches/performance/

After testing the result, we can commit

svn commit -m "Merging the performance branch"

### Tortoise SVN

Right Click on \temp\bob\hanoi -> TortoiseSVN  -> Merge... -> Change the From URL to http:// localhost/repos/sandbox/Hanoi/branches/performance/, use the Show Log to select the From revision (select the first revision, which actually contains the changes). select HEAD as To revision -> Press Dry Run to check the parameters are correct -> press Merge to perform the actual merge.

Now test the merge result and do commit afterwards:

Right Click on \temp\bob\hanoi -> SVN Commit... -> Fill in the commit message -> OK.

mdjun06-4

Now you can use the svn log or TortoiseSVN

About the author

TechWell Contributor's picture TechWell Contributor

The opinions and positions expressed within these guest posts are those of the author alone and do not represent those of the TechWell Community Sites. Guest authors represent that they have the right to distribute this content and that such content is not violating the legal rights of others. If you would like to contribute content to a TechWell Community Site, email editors@techwell.com.

AgileConnection is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, TechWell.com is the place to go for what is happening in software development and delivery.  Join the conversation now!

Upcoming Events

Sep 24
Oct 12
Oct 15
Nov 09