Wednesday, November 24, 2010

Rename files in SVN and Git in Visual Studios

If you haven't shelled out for VisualSVN you have probably had to rename a file in source control manually while it's being tracked in Visual Studio. This can be a pain if things go out of order. So here it is.

This is in C#, which assumes a safe rename refactor exists. Sorry C++!

Svn with Tortoise:
  • Right click file (Foo.cs) in Visual Studio, click "Exclude from project"
  • Find Foo.cs in the Explorer, right click and select TortoiseSVN->Rename...
  • Rename your file.
  • In Visual Studio, right click the folder your file is in (or the project if it's at the top level), and select Add->Existing Item
  • Open the newly renamed file, rename the class FooPrime, hover over the red box below your rename, and select the 'Rename Foo to FooPrime' option.
  • Compile, success!
  • Commit your changes (in Explorer, right click at the top level folder and select SVN Commit)
Git with Git Bash
  • Right click file (Foo.cs) in Visual Studio, click "Exclude from project"
  • cd to the folder containing Foo.cs
  • rename your file with 'git mv Foo.cs FooPrime.cs'
  • In Visual Studio, right click the folder your file is in (or the project if it's at the top level), and select Add->Existing Item
  • Open the newly renamed file, rename the class FooPrime, hover over the red box below your rename, and select the 'Rename Foo to FooPrime' option.
  • Compile, success!
  • Commit your changes (git commit -a)

Note, to move files in TortoiseSVN you have to right click and drag to the new folder (use two explorer windows if the folder isn't easily accessible from your current location). Then select 'Svn move versioned item(s) here...'


No comments:

Post a Comment