Subversion Tip of the Day - Moving Files


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

image

documents are likely named...the following are documents in folder1.1

image

and here are the contents of folder1

image

 

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:

image

Now I'll drag and drop it to folder 2 by using cut and paste:

image

image

This is the revision graph after committing the move:

image

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:

image

When you drop the file(s) to the new location you will be presented with a popup menu

image

Here you can select a SVN move, copy, or export.  I selected 'SVN Move versioned files here'.

image

image

Notice the 'Add' symbol for the moved file.

The revision graph for the file hasn't changed (because the contents are unaltered)

image

The revision graph for the parent folder shows the file move

image

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? 


Posted Sep 12 2007, 11:18 AM by jlockwood
Filed under: ,

Comments

TrackBack wrote
on 10-02-2007 8:49 AM

Pingback from  

Ranjeet wrote re: Subversion Tip of the Day - Moving Files
on 11-20-2007 4:13 PM

Pretty useful, cleared my many doubts and fears in these simple steps for moving the project files work many hours of project team work

Fred wrote re: Subversion Tip of the Day - Moving Files
on 04-12-2008 8:13 PM

Thanks for this. I was looking in the normal TortoiseSVN context menu and was at a complete loss as to how I was meant to move files without losing the history. I'll have to read through the documentation some time, but for now this sorted my problem.

jlockwood wrote re: Subversion Tip of the Day - Moving Files
on 04-25-2008 3:40 PM

I'm glad this was of use to you.  Figuring it out was a bit annoying.  

SVN Tortoise Tip: Moving Files < Rowan’s Blog wrote SVN Tortoise Tip: Moving Files &lt; Rowan&#8217;s Blog
on 11-10-2008 10:21 AM

Pingback from  SVN Tortoise Tip: Moving Files < Rowan’s Blog

Asif wrote re: Subversion Tip of the Day - Moving Files
on 12-11-2008 12:31 PM

Thanks for the tip......I was surprised not to find a move option in the normal right-click context menu of TortoiseSVN......this helped a lot.

The method is easy to use once you have figured it out......but I think it's quite non-intuitive.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Enter the numbers above:
Copyright Los Techies 2007, 2008. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems