Many of you are beginning to use Subversion for your source control repository these days. I am also sure that you have found SVNTortoise to be a welcome addition to Subversion and use it also. Moving files and directories at the command line is a pretty straight-forward affair, but doing so with Tortoise is a little counterintuitive (but never-the-less simple).
Here’s the easiest way that I’ve found to move a file or subdirectory around using Tortoise…
Before I begin, here is folder/file structure for my demonstration
folders are named based on initial hierarchy
documents are likely named…the following are documents in folder1.1
and here are the contents of folder1
Moving a file/directory
Many times (especially early in projects) we may find that we’ve decided that a file should be in another directory. How to move a file was not readily apparent to me and during the error phase of my trial and error I often ended up exporting the file and adding it to the new location. This is bad because I lost history on the file at it’s new location.
Moving the Wrong Way:
Here’s the revision graph for doc1.1.1.txt before a bad move:
Now I’ll drag and drop it to folder 2 by using cut and paste:
This is the revision graph after committing the move:
As you can see the revision history is lost for this item because Subversion was unaware of the move.
Moving the right way:
To move files the right way using Tortoise, highlight the file(s) you want to move and drag and drop to the new location using the RIGHT mouse button.
Revision graph of doc1.1.3.txt before the move:
When you drop the file(s) to the new location you will be presented with a popup menu
Here you can select a SVN move, copy, or export. I selected ‘SVN Move versioned files here’.
Notice the ‘Add’ symbol for the moved file.
The revision graph for the file hasn’t changed (because the contents are unaltered)
The revision graph for the parent folder shows the file move
So, as you can see, the history is preserved. The same process is used to move multiple files and directories to new locations. You can also use ‘Rename’ to move individual files, but I’m not too fond of the approach (it’s also not good if done at the folder level). I do wish that there was a hotkey for this functionality or at least inclusion of the move command into the normal SVN menu. The TortoiseSVN documentation does cover the subject briefly but without the pretty pictures. I sort of wish that I had RTFM before screwing up the history on some of my repositories, but where’s the fun in that?