Confusion in tortoise svn – switching

svntortoisesvn

I am confused in the concept of switching (using tortoise svn). We are a team of 3 developers and I am Dev2 here.

Firstly, I tried switching using following steps (lets say, currently working on trunk and want to start work in branches v1.0)

  1. Right click on /branches/v1.0
  2. Choose tortoisesvn – switch
  3. To Path: /branches/v1.0
    • Head Revision (checked)
    • Switch Depth : Working Copy

Please let me know if I am doing something wrong in above?

But, after that I skipped the switching and then our working gives us following output:

  1. All the developers worked in trunk and then development is over
  2. Created a tag with v1.0
  3. Found bugs in tag v1.0 so created a branch v1.0 from tag v1.0
  4. Need new features as well so Dev1 (Developer 1) continues working in trunk where Dev2 and Dev3 are working on branch v1.0
  5. Dev2 writes code in branch v1.0 and commits
  6. Dev3 get updates in branch (got updates of Dev1) and then writes code in branch v1.0 and commits
  7. Dev1 get updates in branch (got updates of Dev2 and Dev3)
  8. Dev2 and Dev3 get updates in trunk (got updates from Dev1)

All is working fine without switching then what is the concept of switching?

Also, what will happen if I have uncommitted files in trunk while switching?

Best Answer

Imagine if you were working on trunk, and suddenly realized you should have been working on branch 2.3. You could checkout branch 2.3, but you'll lose all of your work. You could try duplicating it, but that could take a long time.

Switching allows you to switch the base of your local copy without losing any of your work. Files you modified will still contain your modifications. Files you added will still be added. Files you deleted will still be deleted.

$ svn co $REPO/trunk/proj1
[...work...work...work...]   #Whoops! Should have been on Release 2.3 branch!
# svn switch $REPO/branches/2.3/proj1
[...work...work...work...]   #Everything is fine and dandy!

Some people use switch to switch their working copy without having to do another checkout. For example, I finish my work on proj1, and now I have some work on the Release 2.3 branch. I simply switch to that branch and save time because I don't have to redownload everything. Plus , I save space!

I highly discourage that thinking because you can easily get confused what your working directory is representing. I've seen some convoluted prompts to extract the branch information and display it in the prompt. However, I name my checkout after my project and branch (or trunk) and I use a separate working directory for each and every project.

Speed shouldn't be an issue. It takes five to ten minutes to do a checkout of a really big Subversion project -- just enough time to get a cup of coffee. Nor, in this era of gigabyte disk sizes, should space be a premium. Using svn switch should not be a common occurrence.

At one time, you sometimes switched if the server that hosted your repository changed. However, there's now a special svn relocate command just for that purpose:

$ svn co svn://repo/proj1   # We were using svnserve
$ svn relocate svn://repo http://repo/svn  #Now we're using Apache https
$ svn relocate http://repo/svn/proj1       #Alternative to the above.