17

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.

bahrep
  • 29,961
  • 12
  • 103
  • 150
Tom Auger
  • 19,421
  • 22
  • 81
  • 104

3 Answers3

12

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"

Tom Auger
  • 19,421
  • 22
  • 81
  • 104
4

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.

user110954
  • 751
  • 8
  • 9
  • 2
    Maybe you could summarize that post in your answer - otherwise if that link ever dies, your answer becomes useless to future people interested in your solution. – Tom Auger Nov 12 '17 at 17:01
3

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
crunchdog
  • 13,078
  • 3
  • 23
  • 19
  • Cool. But it sounds like you're creating a diff file from the trunk repository, not the working copy? Or am I misreading this? – Tom Auger Oct 03 '12 at 13:13
  • No the svn diff command "display local modifications in a working copy": http://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.diff.html so I get my local changes. – crunchdog Jul 23 '13 at 07:31
  • 1
    I'm interested in your solution. What it sounds like you're doing is patching new_branch so it becomes just like working copy. So how do you get new_branch in the first place? – Tom Auger Jul 23 '13 at 13:29