Saturday, February 5, 2011

What is your preferred method for moving directory structures around in Subversion?

I have recently run into an issue where I wanted to add a folder to the directory structure of my project that would become the new 'root' directory for the previously housed files. I've been getting help in a related thread but I wanted to put out a more open ended question to see what a best practice might be.

Essentially, my situation was that I was working on development and realized that I wanted to have a resources directory that would not be part of the main development thrust but would still be versioned (to hold mockups and such). So I wanted to add a resources directory and an implementation directory, the implementation directory being the new root directory. How would you go about moving all of the previous directory structure into the implementation directory?

  • Moves in subversion are done by removing the old files and adding the new ones, so there's nothing special to do. The series of 'svn mv' commands in a loop recommended in the other question should probably work just fine.

    nalply : To be more precise: http://svnbook.red-bean.com/en/1.5/svn.ref.svn.c.move.html says a svn move is equivalent to a svn copy then svn delete. And since svn copies are cheap copies, svn moves are also cheap.
    From Allen
  • You can do it pretty easily if you use some GUI for SVN. Personally I love TortoiseSVN for when I'm working in Windows. You just open up the "Repository Browser", right-click on some folder, and choose "Move...". Or, you have the option of doing it straight from within Windows Explorer, drag the files/folders you want to move with the RIGHT mouse button, when you drop them in their new location you'll get a menu, one of the options is "Move in SVN".

    nickf : Does this have any effect on being able to get older revisions of these files? As I understand it, a move is actually a "delete" of the files in the original location, and an "add" of the files in the new location.
    davr : nope, it actually does preserve the history. A move is actually implemented as a "copy" and then a "delete". And since branch and tag are actually implemented as "copy" as well, they all preserve history in the same way.
    Mauli : depending on how you do it, don't forget to switch your working copy afterwards.
    From davr

0 comments:

Post a Comment