How To: Safely Rename a Source-Controlled File in Visual Studio .NET
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.
2.
Check in
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
3.
Exclude
the file from the project (if C++ project or there is no "Exclude" command, see
Note #2 below).
4.
Rename the
file in the SCC database using your source control provider’s standalone
application (for example, Visual SourceSafe
Explorer).
5.
Get Latest
Version of the file in the source control
database.
6.
In Visual
Studio .NET, select the project and click Show All
Files.
7.
Include
the newly renamed file in the project.
8.
Delete the
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
below.)
Notes about this procedure:
- Can only be used to rename files, not
projects. - C++ projects and other reference-based projects types
do not support the Exclude from Project/Include in Project commands because
they are not 'directory-aware' like VB and C# projects. To rename files in a
source-controlled C++ project, Remove the file from the project, rename the
file in the source control database, and then re-add the file to the project
using the Add Existing Item command. - Web projects are pure, directory-based projects. All files that reside in
the project folder on disk appear in the project in VS.NET. If you work with
other developers, when renaming files in a source-controlled Web project, you
should try to inform your teammates of the change as soon as possible to avoid
confusion.
Il
presente posting viene fornito “così come é”, senza garanzie, e non
conferisce alcun diritto.
Comments
Anonymous
September 23, 2003
:)Nah, no blog.. yet..Anonymous
October 10, 2003
No need to exclude the file from the Vs.NET project, you can simply1- rename the file in VS.NET2-Rename the file in VSS, with the new name you gave in VS.NET3- Check-in the file in VS.NETAnonymous
March 18, 2004
Surrogate primary keys for SourceSafe?Anonymous
July 19, 2004
Funny, the MS-SCCI supports the rename functionality directly, but it appears that MS has not enabled the functionality in VS.NET. I've been playing with our own SCCI implementation against VS.NET and just cannot get it to work. Maybe i'll just have to tell our own customers to user your suggestion.
Thanks for the info.
--CoreyAnonymous
April 17, 2006
wow, i'd like to solve your problem, use <a href="http://www.yaodownload.com/utilites/file-disk-management/filemonkey/">FileMonkey</a>">http://www.yaodownload.com/utilites/file-disk-management/filemonkey/">FileMonkey</a> can rename your file safely.
http://www.yaodownload.com/utilites/file-disk-management/filemonkey/Anonymous
September 03, 2006
Thank you so much for this great post about <a href="http://eteamz.active.com/legalbusiness/files/online-shopping-cart.html"">http://eteamz.active.com/legalbusiness/files/online-shopping-cart.html" title="online shopping cart">online shopping cart</a> and [URL=http://eteamz.active.com/legalbusiness/files/online-shopping-cart.html]online shopping cart[/URL]Anonymous
September 03, 2006
Thank you for this great post about <a href="http://cahoot.builtfree.org/cyprus-in-property-sale.html"">http://cahoot.builtfree.org/cyprus-in-property-sale.html" title="cyprus in property sale">cyprus in property sale</a> and [URL=http://cahoot.builtfree.org/cyprus-in-property-sale.html]cyprus in property sale[/URL]Anonymous
September 04, 2006
Thank you so much for this great post about <a href="http://eteamz.active.com/yourbusiness/files/online-horse-betting.html"">http://eteamz.active.com/yourbusiness/files/online-horse-betting.html" title="online horse betting">online horse betting</a> and [URL=http://eteamz.active.com/yourbusiness/files/online-horse-betting.html]online horse betting[/URL]Anonymous
September 06, 2006
Thanks for the great tips about <a href="http://AgentInsurance.bravehost.com/home-equity-loan-rate.html"">http://AgentInsurance.bravehost.com/home-equity-loan-rate.html" title="home equity loan rate">home equity loan rate</a> and [URL=http://AgentInsurance.bravehost.com/home-equity-loan-rate.html]home equity loan rate[/URL]Anonymous
September 06, 2006
Thanks for the great tips about <a href="http://newbusinessloan.bravehost.com/accommodation-france-holiday-in.html"">http://newbusinessloan.bravehost.com/accommodation-france-holiday-in.html" title="accommodation france holiday in">accommodation france holiday in</a> and [URL=http://newbusinessloan.bravehost.com/accommodation-france-holiday-in.html]accommodation france holiday in[/URL]Anonymous
June 12, 2009
PingBack from http://cellulitecreamsite.info/story.php?id=112Anonymous
June 12, 2009
PingBack from http://toenailfungusite.info/story.php?id=1311Anonymous
June 15, 2009
PingBack from http://mydebtconsolidator.info/story.php?id=139Anonymous
June 15, 2009
PingBack from http://workfromhomecareer.info/story.php?id=15578Anonymous
June 16, 2009
PingBack from http://fixmycrediteasily.info/story.php?id=11333