I was on a Live Meeting the other night, trying to explain how the switch command in subversion works. After the meeting was over I thought that explaining the command in a blog post would be a excellent idea. It would give me better understanding of the command and hopefully help someone else.
Simply put, the switch command is a shortcut for moving from one branch to another. It can be used to merge changes to a trunk branch. In this blog post I will demonstrate how to merge changes to trunk with and without the switch command.
When the time comes to merge your changes back to the main line of development, you have two options. One option is to check out the main line of development, and then do a merge back to your branch. Below are the steps for doing this.
$ mkdir app-trunk
$ cd app-trunk
$ pwd
C:\DOCUME~1\ZACHYO~1\MYDOCU~1\app-trunk
$svn checkout file:///C:/demo/trunk
A trunk\code.txt
Checked out revision 10.
After reviewing the above commands you can see there is only one code file. Now let’s see what is in the working copy.
$ cd ..
$ cd app
$ pwd
C:\DOCUME~1\ZACHYO~1\MYDOCU~1\app
$ls –lrt (The code2.txt file needs to be merge back to truck)
total 8
-rw-rw-rw- 1 Zach Young 0 5 2008-11-09 15:16 code2.txt
-rw-rw-rw- 1 Zach Young 0 13 2008-11-09 15:16 code.txt
$svn status (Run this to confirm everything has been committed)
Now that you have both a working copy and the trunk check out you can do a merge. The below window will show how this merge is done.
$ cd ..
$ cd app-trunk
$ pwd
C:\DOCUME~1\ZACHYO~1\MYDOCU~1\app-trunk
$svn update (Make sure no changes have been committed.)
At revision 10.
$svn merge --reintegrate file:///C:/demo/branch/new
--- Merging differences between repository URLs into '.':
A code2.txt
U .
$svn commit -m "Add the code2.txt file"
Sending .
Adding code2.txt
Committed revision 12.
The other option to merge your changes to the trunk is by using the switch command. Using this command you can traverse to the main line of development. Below are the steps for doing this. Notice by using this method you do not have to check out the trunk.
$pwd
C:\DOCUME~1\ZACHYO~1\MYDOCU~1\app
$svn sw file:///C:/demo/trunk
D code2.txt
U .
Updated to revision 13.
$svn merge --reintegrate file:///C:/demo/branch/new
--- Merging differences between repository URLs into '.':
A code2.txt
G .
$svn status (Double check the merge.)
M .
A + code2.txt
$svn commit
Log message unchanged or not specified
(a)bort, (c)ontinue, (e)dit :
c
Sending .
Adding code2.txt
Committed revision 14.
$svn sw file:///C:/demo/branch/new (Back to the working copy)
As you can see with the switch command, you can save a few steps.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5