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?
That means the Subversion status is normal. As soon as you start editing a file, the status changes to modified and the icon overlay then changes to a red exclamation mark. That way you can easily see which files were changed since you last updated your working copy and need to be committed.
Renaming a file. Normally you can just use SVN Rename on the context menu. This is analogous to the Move command described in the Moving or Copying a file recipe. It is almost as if you are doing two separate steps: an Add operation with the new name and a Delete operation of the old name.
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.
To tell TortoiseSVN that a file was renamed, right click the folder that contains it and choose Commit... or Check for modifications. You will see the old file name with status "missing" and the new file name with status "unversioned".
Then browse to the target folder, right click and choose TortoiseSVN→ Paste. For moving files, choose Context Menu→ Cutinstead of Context Menu→ Copy. You can also use the repository browser to move items around. Read the section called “The Repository Browser”to find out more. Do Not SVN Move Externals
Next Deleting, Moving and Renaming Subversion allows renaming and moving of files and folders. So there are menu entries for delete and rename in the TortoiseSVN submenu. Figure 4.34. Explorer context menu for versioned files Deleting files and folders Use TortoiseSVN→ Deleteto remove files or folders from Subversion.
Select the files you want to copy, right click and choose Context Menu→ Copyfrom the explorer context menu. Then browse to the target folder, right click and choose TortoiseSVN→ Paste. For moving files, choose Context Menu→ Cutinstead of Context Menu→ Copy. You can also use the repository browser to move items around.
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:
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:
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).
Right Click on the file > TortoiseSVN > Rename.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With