38

I made the mistake of creating a Subversion repository without the usual trunk, branches, and tags directories. That is, the root directory of the project maps to the root directory of the repository. Now I want to create a feature branch, but there's no good place to put it. What I'd like to do is move / to /trunk, preserving its properties and history. Am I out of luck?

0

9 Answers 9

35

The clean way to do this is using svnadmin to dump out the whole repository using

svnadmin dump

Then create a new repository with the trunk directory at the root, and reload the dump with

svnadmin load --parent-dir trunk

If you do an svn move then that will mess things up if you ever update back to a revision before the move, since the files will move back to their previous location, which is probably not what you want.

4
  • 2
    @sleske - I've handled exactly this problem before - see my note about the problems of doing an svn move. This is the correct way to do it. May 2, 2010 at 15:00
  • I've not had a chance to try this, but it sounds like exactly the solution I'm looking for.
    – Adam Siler
    May 2, 2010 at 15:49
  • Another plus of the excellent advice @therfromhere gives is that future svndumpfilter runs are going to work out. If you move the tree svndumpfilter is going to have problems.
    – thekbb
    Jun 29, 2011 at 15:32
  • But if I have repository with multiple modules calc calendar ... and I want to change it into calc/trunk calendar/trunk ... then it is almost impossible. I may hack the dumo file, but when it contains come directory creations it becomes a nighmare.
    – xmedeko
    Jul 27, 2011 at 12:22
26

Used therefromhere's answer, which worked fine, but wanted to add the commands including the parameters, i.e. as executed on the svn server's command line:

  1. Dump your existing repository into a file:

    svnadmin dump /path/to/myrepo/ > /some/dir/myproject.svndump
    
  2. Create a new repository:

    svnadmin create /path/to/mynewrepo/
    
  3. Add the trunk/ folder and commit it, in the working copy directory:

    mkdir trunk; svn add trunk; svn commit trunk -m "Add: trunk folder"
    
  4. Load the dumpfile into the new repository using trunk as parent-dir:

    svnadmin load --parent-dir trunk /path/to/mynewrepo/ < /some/dir/myproject.svndump
    
1
  • 3
    It is easy to miss in the instructions, but this should be run on the server, not the working copy. Otherwise you'll get "Can't open file '/path/to/myrepo/format': No such file or directory."
    – DavGarcia
    May 1, 2013 at 19:35
2

The easiest way would be to create a 'trunk' directory, then move everything else into it. You'll have to copy any properties manually, but it shouldn't be a big deal. The history is per-file, so it should remain.

The other issue to consider is whether anybody else has the repository open. It'll be difficult to merge, so make sure everyone has their changes checked in before you do this.

3
  • 1
    It is the easiest way, but you need to beware that if you ever update back to a revision before the move then unexpected things will happen (your working copy will delete itself ;) ) May 2, 2010 at 15:02
  • Agreed. It's a bit trickier to use svnadmin but the results are better, and the merge issues are no worse than in the naïve method. I voted your answer up. May 2, 2010 at 15:06
  • Conceptually, what is now /trunk is what used to be /, however this solution does not maintain history in a way that represents this. Running svn log on trunk will not show the history that was previously available on the root folder, which I think is what the OP wants.
    – HappyDog
    Sep 16, 2019 at 9:49
1

Can’t you just create the trunk dir and move everything from / to trunk?

1

As the other answers point out, just doing a svn mv into the trunk directory will do this. To then update your working copy, check out the svn switch command.

1
  • This seems to make the most sense, I wish I could vote ^3+. I am uncertain what command line commands happened under the covers but with TortoiseSVN I used Repo-Browser to create a "trunk" directory and then dragged-and-dropped the versioned contents into the trunk directory with "Move to trunk" appearing as a tooltip. All logs were retained. I failed to use svn switch, I just deleted the .svn metadata directory and re-checked out, but I'm sure svn switch would have made more sense.
    – Jon Davis
    May 4, 2012 at 23:31
1

No just create a trunk folder and move all the contents of the root to it. You can do it from explorer or through the repo-browser, the history will persist.

1

You need to create /trunk and do an svn move of all contents of root inside the trunk and then commit.

After that you'll switch your working copy to /trunk.

1
  • This will move the files alright, but if you do an svn log on the trunk folder then all you'll see is the initial commit that moved the files. You won't get the full history, which I think is what the OP wants.
    – HappyDog
    Sep 16, 2019 at 9:47
1

There are some gotcha's or limitations with some of the discussed approaches. The post below discusses another approach, which involves dumping the repo and editing the file paths. This has the benefit that moved files will be properly modified too.

http://dotslashstar.blogspot.com/2011/06/svn-hack-insert-missing-trunk-root.html

-2

Quick example of how I did it.

I wanted to move file:///svn/myRepo to file:///svn/myRepo/trunk

cd /  
svnadmin dump /svn/myRepo > my.dump  
killall svnserve  
sudo rm -r -f /svn/myRepo  
svnadmin create /svn/myRepo  
svnserve -d -r /svn  
svn mkdir file:///svn/myRepo/trunk -m "Created trunk dir"  
svnadmin load /svn/myRepo --parent-dir trunk < my.dump

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.