47

I am working a project that does not have a trunk / branches / tags directory structure - ie. everything is in the root of the svn repo.

I would like to create a trunk directory and in the root directory, and move everything in the root directory into the new trunk directory.

What is the best way to do this?

The first thing I considered was

svn mkdir trunk
(for each file or directory that is not called trunk: )
svn mv FILEorDIR trunk/

But this effectively deletes every file and then adds it again. Is there a better way?

Thanks.

7 Answers 7

23

I had exactly the same problem and solved it after looking through several different pages (this one included). Here's my solution:

Note: Before you begin, if you plan to use svn switch to keep your working copy and avoid checking out the repo again, it's best to make sure your working copy is up to date and has no uncommitted changes.

On with the solution...

//REPO_URL = The URL for the repo on the SVN server.
//In my case it was https://IP_ADDRESS:PORT/svn/my_repo

//Make the trunk dir in the root of your SVN repo
svn mkdir REPO_URL/trunk -m "making trunk dir"

//Move everything from your root dir to your new trunk dir
svn move REPO_URL/A_FOLDER REPO_URL/trunk/A_FOLDER -m "moving folders to trunk"
svn move REPO_URL/ANOTHER_FOLDER REPO_URL/trunk/ANOTHER_FOLDER -m "blah"
svn move REPO_URL/A_FILE.TXT REPO_URL/trunk/A_FILE.TXT -m "moving files to trunk"
//Keep going until you've moved everything from your root dir to the trunk dir...

So now, on your SVN server, everything is in the trunk folder. Sweet!

But my repo is 60GB and on a remote server. I'd rather not check that out again. svn switch will let you point your existing working copy to the new trunk dir so you can continue to work with the copy you have. Go into the root folder of your working copy and run svn switch REPO_URL/trunk --ignore-ancestry. It should say At revision X where X is the revision after you moved all of your files from the root directory into the trunk directory. That's it! Maybe do an SVN update for good measure :)

1
  • 2
    seems like a better answer than the one that was selected
    – Mike D
    Jun 3, 2015 at 2:30
10

This is similar to the way I've done it in the past. Your solution actually copies each file, then deletes the original. Because of the way Subversion implements copies, the history for every file is preserved.

After doing this, you can point existing checkouts at the new location using svn switch.

2
  • can you give the exact command for svn switch? Also, is there a way to force switch to not update to the latest revision in the working copy where it is run?
    – Vijay Dev
    Jul 2, 2010 at 13:44
  • @Vijay Dev: I recommend the svn switch documentation for full details. Jul 2, 2010 at 21:44
3

If you are using eclipse IDE and Subclipse for SVN then you can go ahead and create folders in SVN and move all the files/dir from root to the trunk directory and then checkout the ProjectName/trunk to you eclipse workspace...

1
  • 1
    Additionally, if you're intending to copy to a clean repository (one which hasn't any project checked in, so it hasn't trunk/branches/tags structure), in Eclipse you can create the trunk/branches/tags structure with Repo>New>Project Structure...>Monolithic. After that, just copy/paste all the elements from the source repo.
    – Saran
    Apr 6, 2012 at 11:28
2

Old post but I too had the same issue with all my repos were in the root and not in trunks. This presented a problem when trying a simple git svn clone command. After hours of trial and error, it was a simple:

git svn clone --username byname http://www.MySVNserver.com:81/repos/project1 --no-metadata --trunk=.

1

I did this myself serveral times and learned this: If you want to keep the history of the previous SVN root directory + keep all SVN properties (like ignore) you must do it the following way. Notice: I did it all with TortoiseSVN, because it is very easy this way. But you may have also success with the command line. Below you find a description to do it with CLI too.

Do not forget to add appropiate SVN messages to each action, so you know later nice and clean what have been done.

Example repo: /svn/my_project

Steps for TortoiseSVN:

  1. Rename current project directory /svn/my_project to trunk /svn/trunk
  2. Create a new directory /svn/my_project
  3. Move /svn/trunk to /svn/my_project
  4. Switch working copies to new path. Check the checkbox "Ingore ancestry".
  5. Relax

Steps for the CLI (untested!):

  1. Copy the directory to a new directory /svn/trunk/
  2. Delete the old directory /svn/my_project/
  3. Copy the /svn/trunk/ directory to a new directory /svn/my_project/trunk
  4. Delete the /svn/trunk/ directory
  5. Switch working copies to new directory
0

You may want to look into the svnadmin tool.

To be honest I have not tried this before, and you'll probably get an answer from someone who has, but you can work from something like this:

You should be able to init a new repository, create a 'trunk' directory in it, then dump your previous repository into the 'trunk'.

0

Here give the way of using svn+ssh method to create the trunk folder in the svn root in unix terminal. "projectname" is the root "Identifier" when you create the project in svn:

svn mkdir svn+ssh://username@host/projectname/trunk -m "Create the trunk folder"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.