120

I've been working on code checked out from the development line and discovered that the changes made might be breaking changes and need to be moved to an experimental branch before committing to the main dev tree. However, I don't have the experimental branch checked out and I don't want to lose the changes that have already been made.

Is there a way to commit the changes in the working folder to a different branch than originally checked out?

jjmontes
  • 24,679
  • 4
  • 39
  • 51
Paul Alexander
  • 31,970
  • 14
  • 96
  • 151

3 Answers3

133

You should create a branch from a known sourceURL (this would be your 'development line' you mentioned in the question) first:

svn copy sourceURL branchURL

Then, switch to that branch:

svn switch branchURL

And commit your changes:

svn commit
ryanprayogo
  • 11,587
  • 11
  • 51
  • 66
57

You could do it in the TortoiseSVN like that:

  • Right click on the directory where are the changes you want to branch. It must not be the root of the repository, less to duplicate in that way;
  • Select TortoiseSVN -> "Branch/tag...";
  • Set To URL: "svn://host/repository/FooBar/branches/FooBarBranchName";
  • Make sure [*] Working copy is selected. This will ensure the changes are commited;
  • Log message: "Experimenting with flies :)";
  • Optional: Tick [*] Switch working copy to new branch/tag. This is useful if you are planning to keep working on the new branch. Although you can switch to it later too.
  • Try to find the OK button. Hint: it is in the lower part of the window centred.

Enjoy!

J Pollack
  • 2,788
  • 3
  • 29
  • 43
  • What do you mean by "It must not be the root of the repository, less to duplicate in that way"? – thekozak Mar 04 '15 at 20:47
  • I recommend not to choose the root folder with all the irrelevant sub-folders which are not subject to be modified in the branch. Later it will be easier to merge the (smaller) branch back to trunk. – J Pollack Mar 05 '15 at 09:24
  • In my case committing only that folder caused issues because the software depends on superfolders too. I think that's most often the case. I think for most use cases it's better to just commit the whole thing, so committing from the root I say is recommended. – ikku100 Dec 10 '15 at 11:36
  • @ikku100 if there are no changes in those superfolders, how would it matter? – simpleuser Apr 28 '16 at 05:43
  • It could because people later on might commit changes there, but I guess you can check out the correct revision of the superfolder and then checkout the branch for the subfolder. Which is more work than just committing from the superdir, I think. – ikku100 Apr 28 '16 at 16:49
  • Note that this approach will create the folder structure. No need to create the branch folder before performing the action – Frostrar Mar 09 '18 at 10:43
8

You can create a new branch directly from your working directory and switch the working directory to that branch.

The commands are svn copy and svn switch

Dima
  • 38,860
  • 14
  • 75
  • 115