Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I branch a modified working copy with SVN?

Tags:

branch

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.

like image 836
Tom Auger Avatar asked Oct 02 '12 13:10

Tom Auger


People also ask

Can you branch in svn?

A SVN branch copies the trunk and allows you to make changes. When the new feature is stable, the branch is merged back. Here's a basic step-by-step overview of SVN branching and merging. Create a branch using the svn copy command.

How do I checkout a working copy in svn?

svn Getting started with svn Checking out a working copy Your local copy of the project is called a working copy in Subversion and you get it by issuing the command svn checkout <URL> where <URL> is a repository URL. e.g. Alternatively, you can use svn co <URL> as a shorthand in order to checkout a local copy.

How do I tag a revision in svn?

If you want to create a snapshot of /calc/trunk exactly as it looks in the HEAD revision, make a copy of it: $ svn copy http://svn.example.com/repos/calc/trunk \ http://svn.example.com/repos/calc/tags/release-1.0 \ -m "Tagging the 1.0 release of the 'calc' project." Committed revision 902.


2 Answers

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"

like image 144
Tom Auger Avatar answered Sep 28 '22 01:09

Tom Auger


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
like image 29
crunchdog Avatar answered Sep 28 '22 00:09

crunchdog