How to tell TortoiseSVN that a renamed file was renamed (not deleted and re-added)?

zachary picture zachary · Feb 3, 2010 · Viewed 9.4k times · Source

Using VisualSVN and TortoiseSVN here.

I've renamed my file. I notice it say add and delete which to me means history may be erased?

What is the best way to rename a file without losing history in Subversion?

Answer

alexandrul picture alexandrul · Feb 3, 2010

The history won't be erased, but you will lose history tracing, as it would seem to be two unrelated files.

From TortoiseSVN docs:

If you want to do a simple in-place rename of a file or folder, use Context Menu → Rename... Enter the new name for the item and you're done.

Repairing File Renames

Sometimes your friendly IDE will rename files for you as part of a refactoring exercise, and of course it doesn't tell Subversion. If you try to commit your changes, Subversion will see the old filename as missing and the new one as an unversioned file. You could just check the new filename to get it added in, but you would then lose the history tracing, as Subversion does not know the files are related.

A better way is to notify Subversion that this change is actually a rename, and you can do this within the Commit and Check for Modifications dialogs. Simply select both the old name (missing) and the new name (unversioned) and use Context Menu → Repair Move to pair the two files as a rename.

Many other cases are covered.

Update

The history is lost when Subversion doesn't know it's a rename, like this:

  • the old file name is aa.txt, and it's renamed by hand to bb.txt
  • the new file name bb.txt is added to subversion
  • in the commit dialog, aa.txt appears as missing and can be marked as deleted, and bb.txt appears as added
  • the result is that history is lost, SVN show log from the contextual menu will show only bb.txt

To preserve file history, you need to use the Rename option from the contextual menu (or from the command line). IF you already renamed the file then:

  • the old file name cc.txt will appear as missing
  • check the Show unversioned files option to see the new file name dd.txt, which is marked as non-versioned
  • select both file names and choose Repair move from the contextual menu, which results in cc.txt being marked as deleted and dd.txt being marked as added (+)
  • after commit, history will be preserved, and in the log you will see both file names if you uncheck the Stop on copy/rename option.

So, to resume, in the commit dialog added (+) means that history will be preserved, and added means loosing the the history. In both cases, the old file name will appear as deleted.

Update 2

When I say that history is lost, please understand that the previous information still exists, but it won't be present in the log of the current file name, and you must manually track it (which is not quite a pleasant thing to do).