Tom Auger
Tom Auger

Reputation: 20066

How do I branch a modified working copy with SVN?

I started working on what I thought would be a small change to trunk, walked away for a month and now I realize this is really a whole side-project (full of bugs) that really needs its own branch. Furthermore, once I've branched these changes off, I want to reset my working copy back to what's currently in trunk so I can help out the main development effort and high-priority items before coming back to this side project when there's time.

So:

  1. I would like to make a new branch, based on my working copy, without having to check in my working copy (it IS up to date with the latest HEAD revision though)

  2. Once I have forked my working copy, I would like to basically remove all changes that are in the branch, and just set it to match the current HEAD revision in trunk.

What's the procedure? I'm using TortoiseSVN, but even command line instructions would be helpful.

Upvotes: 19

Views: 19194

Answers (3)

user110954
user110954

Reputation: 761

In case you prefer to continue working on in the same folder, this post shows how to.

Basically svn copy to create a branch svn switch to point to new branch from the same working copy and svn commit to commit your changes.

Be sure you branch off your from the same branch/revision you started modify (svn info to check) or you may endup with many conflicts after switch.

Upvotes: 4

crunchdog
crunchdog

Reputation: 13468

In command-line you can create a patch with the subversion "diff" command, and then apply it to your new branch with the subversion "patch" command. (You can read about these commands by executing 'svn help diff' and 'svn help patch'). Let's say you have the trunk and a branch called new_branch in the same parent directory.

cd trunk
svn diff > ..\my_stuff.diff

Now you have the patch, then apply it to your newly created branch.

cd new_branch
svn patch ..\my_stuff.diff 

You can dry run the patch first by adding the --dry-run flag to the patch command, to see if anything strange happens before actually applying it.

svn patch ..\my_stuff.diff --dry-run

Upvotes: 3

Tom Auger
Tom Auger

Reputation: 20066

So I've tried two methods to branching my working copy without checking it in, not sure which one is going to end up being the best method:

Method 1: Copy entire directory to new branch

  • Right-click on your working copy folder and choose Tortoise SVN > Repo Browser
  • In Repo Browser create a new directory called "branches" at the same level as "trunk"
  • Inside the "branches" dir, create a new dir with the "name" of your branch (by "name" I mean, a label that will identify this branch, so e.g.: if you're working on a special notification system in this branch, call it "notifications" etc...)
  • Now, still in Repo Browser right click and choose "Add Folder" and select your local working copy
  • This will take a while, since all files (including .svn files) are being copied. This also copies unversioned files and files that you have svn:ignored, which may not be desired.

Method 2: use Branch/tag

  • Right click your working copy folder and choose Tortoise SVN > Branch/tag...
  • It opens up the Repo Browser, so create a new directory "branches" and then inside that, a new dir with the "name" of your branch
  • You select the "Working Copy" button in the "create copy in the repository from" section. This is what will commit the diff of your local changes to this branch
  • This seems to only copy the files that are DIFFERENT from what's in the HEAD revision.
  • However, if you then use the Repo Browser again to see what's in there, the entire HEAD revision + your local changes are all in there

It looks like Method 2 is definitely preferable.

Then, to clean up, it was a matter of Tortoise SVN > Revert... and "Delete all unversioned"

Upvotes: 13

Related Questions