Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Propogate file renames in Visual Studio (2013) to GIT as GIT renames?

We use GIT and Visual Studio 2013 (Ultimate + Professional versions). The code for the solution and projects is in GIT and anytime we rename the file in Visual Studio, GIT sees them as

Before rename

c:\temp\testCodeSnippets>git status
# On branch master
nothing to commit (working directory clean)

After rename (from Visual Studio)

c:\temp\testCodeSnippets>git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    OldName.cs
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       NewName.cs
no changes added to commit (use "git add" and/or "git commit -a")

Renaming via git mv

c:\temp\testCodeSnippets>git mv OldName.cs NewName.cs

c:\temp\testCodeSnippets>git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       renamed:    OldName.cs -> NewName.cs
#

Basically, the renames performed in VS still need some manual work. Equally important; a lot of these renames happen when refactoring from inside the IDE i.e. a class/member/etc gets renamed and all references get changes. If the namespace or classname changes, the files get renamed.

So, is there any setting to toggle, any tool to install, any deity to appease so that renames from Visual Studio get mapped as renames to GIT too (like git mv does to make it smooth)?

like image 849
DeepSpace101 Avatar asked Feb 10 '14 03:02

DeepSpace101


People also ask

How do I rename a file in Visual Studio Git?

Right-click on a file in the File Explorer and choose "Rename (git-mv)".

How do I rename a file in Git?

In your repository, browse to the file you want to rename. In the upper right corner of the file view, click to open the file editor. In the filename field, change the name of the file to the new filename you want. You can also update the contents of your file at the same time.

How does Git know a file was renamed?

Git keeps track of changes to files in the working directory of a repository by their name. When you move or rename a file, Git doesn't see that a file was moved; it sees that there's a file with a new filename, and the file with the old filename was deleted (even if the contents remain the same).

What is git MV?

git-mv - Move or rename a file, a directory, or a symlink.


1 Answers

Core git (the command-line application) only identifies renames by detecting them between files that are staged for addition and files that are staged for deletion.

Visual Studio, however, does not stage changes you make during operation. Instead, it will stage the changes at commit time. There are several reasons for this, but primary is that staging a change places the file in the object database and doing this for each save would be incredibly costly.

You will need to manually stage the changes using git add and git rm and your renames will be reported as it always will, by comparing the added changes to the renamed changes.

(Note that Visual Studio - since it doesn't stage your changes as you go - examines both staged and unstaged files for rename detection. So Visual Studio will report renames before core git does. However, they should show the same results in status when you stage those changes.)

like image 72
Edward Thomson Avatar answered Sep 29 '22 14:09

Edward Thomson