Last Friday, I posted a
procedure for renaming source-controlled items in VS.NET that fails to
mention one big gotcha: If you rename a file using Visual Studio .NET's Rename
command, you lose its history--or at least the continuity of such--for
the file in your source control database*. Why? Because VS.NET renames a
file by essentially copying it on disk and deleting the original. If the renamed
item is under source control, SCCI asks you to check out the project
file, marks the newly-created (renamed) file, as a "pending add"
to the source control database, and when you check in the
project, adds the new file to the database alongside the old, unrenamed file; a
master copy of which remains in the source control database. Unlike
what happens in the filesystem, the old, unrenamed version of the file is not
deleted from the SCC database. The problem with this is that while you
might expect the source control history of the file to 'follow' it to
the renamed version, it remains with the old, unrenamed database
version of the file instead.
Many thanks to reader AsbjornM (no blog?) for calling out the existence
of an alternative procedure for renaming/moving files in a way that
retains history for the altered file.
Disclaimer: When developing source-controlled projects in Visual Studio .NET,
Microsoft recommends that you perform all source control operations in the
IDE. Generally, you should not use your standalone source control
application to directly manage a VS.NET project file in the database.
When RENAMING a file in VisualStudio.NET however, you can (and perhaps
should) forget this disclaimer. So let's try this again.
To rename a source-controlled file in Visual Studio .NET
2002 or 2003 in a way that retains file history
1. Inform all project enlistees that you plan to rename a file
in the project.
the file to be modified and, if your database permits multiple checkouts,
ask all project enlistees to check in the entire project to which the
file or project belongs
the file from the project (if C++ project or there is no "Exclude" command, see
Note #2 below).
file in the SCC database using your source control provider’s standalone
application (for example, Visual SourceSafe
Version of the file in the source control
Studio .NET, select the project and click Show All
the newly renamed file in the project.
old, un-renamed version of the file from disk, if desired, and notify your
teammates that they should do so as well. (If Web project, see note #3
Notes about this procedure:
presente posting viene fornito “così come é”, senza garanzie, e non
conferisce alcun diritto.