views:

411

answers:

6

using visual svn and tortoise svn here

I 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?

+2  A: 

The file's history will not be erased. Previous commits won't be affected. However, you can use svn move to properly move the file.

ezod
+5  A: 

Right Click on the file > TortoiseSVN > Rename.

Mendy
visualsvn tag and the question might indicate that he already renamed with visualsvn, if that's the case it's correctly added (with history )/deleted (that's what a Subversion rename is)
Sander Rijken
+2  A: 

The history is not erased by doing a rename from the TortoiseSVN Context Menu. If you want to see the changes from before the rename, make sure you don't use the --stop-on-copy flag when looking at the change log:

svn log -v -r 0:N --limit 100 [--stop-on-copy] PATH
  or
svn log -v -r M:N [--stop-on-copy] PATH

see here for reference: http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-cli-main.html

Mike Sherov
+1  A: 

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).

alexandrul
An even better way is to use a Subversion-aware IDE which will rename the files correctly...
JesperE
An even better way is to use Git or Mercurial :D but sometimes you won't have a choice about the IDE and the other tools used.
alexandrul
@JesperE: he mentions he's using a Subversion-aware IDE plugin.
Sander Rijken
Let me see: he already renamed the file and subversion doesn't know it (quote: I notice it say add and delete), so I point him to the subversion docs and did some spoonfeeding - quoted the repairing procedure. So enlighten me: why the downvote?
alexandrul
add and delete is *exactly* what you see when you `svn move` a file
Sander Rijken
@Sander Rijken : unless the history is preserved and then you see deleted and added (+) in the commit dialog
alexandrul
A: 

A delete and add with history is the expected thing to happen when renaming a file in Subversion. History is not lost.

VisualSvn and AnkhSvn both capture the events from Visual Studio that a file is being renamed, and do the right thing.

Sander Rijken
A: 

For file operations like moving and renaming I normally prefer to use the TortoiseSVN Repo Browser, followed by a local SVN Update. Of course that's only appropriate if you want your operation to be committed to the repository straight away.

Richard Ev