4

Is there an extension to Visual Studio 2010 / Resharper, that will cause files moved or renamed during a refactoring to be git moved appropriately? Right now every time I move a file I have to manually git rm / git add, or else if I git move it directly I have to mess around in Visual Studio to get it to recognize the moved files.

I'm using Visual Studio 2010, Resharper 7.1.2, Git Bash (git version 1.8.1.2) and the Git Source Control Provider.


Update: I know git auto-detects moves once a files been rm'd and added. But I don't want to have to manually rm every file that's been moved, and since other tools (e.g. IntelliJ IDEA) seem to be able to do it for me, it seems reasonable that VS should be able to as well.

David Moles
  • 48,006
  • 27
  • 136
  • 235
  • Git should automatically recognize when a file has been moved once you staged everything. You might be interested in this question [How does git detect similar files, for its rename detection?](http://stackoverflow.com/questions/7938582/how-does-git-detect-similar-files-for-its-rename-detection) – Roman Mar 15 '13 at 01:18
  • Right, but having to stage all the deletes is a serious pain, especially because git-bash can't tab-complete files that aren't there any more. Other IDEs (including Intellij IDEA) handle it fine, so I don't see any reason why VS/Resharper shouldn't be able to. – David Moles Mar 15 '13 at 15:11
  • If there's an easy way to `git rm` all (and only) the files that have been deleted from the working copy, that'd be almost as good. Then I could get the git index up to date in just two commands. – David Moles Mar 15 '13 at 15:12
  • According to the last comment to [another answer](http://stackoverflow.com/a/14835456/164966), `git rm` should work with wildcards. If you use something like [Git Extensions](http://code.google.com/p/gitextensions/), the commit dialog will let you easily select and stage all of the deletes. – Roman Mar 15 '13 at 16:10
  • It'll work with wildcards, but constructing the proper wildcard is non-trivial. Based on the "Removing files that have disappeared from the filesystem" section of the [git-rm docs](https://www.kernel.org/pub/software/scm/git/docs/git-rm.html), I've added a shell script that calls `git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached`, which git-rms everything that's missing from the working copy, and the combination of that with `git add .` is reasonably effective so long as the working copy's otherwise clean, but it's still not as good as proper tools integration. – David Moles Mar 15 '13 at 17:09
  • Consider installing Git Extensions. Git Source Control Provider that you are already using can pull those commands into its own menu so the workflow comparable to what you're (probably) already doing. – Roman Mar 15 '13 at 19:06

1 Answers1

0

For me (with VS2012, msysgit and Git Source Control provider) it works like this:

  1. I rename a class using ReSharper C-R C-R.
  2. ReSharper automatically renames the file
  3. In the "Pending Changes" view I get a "Delete" of the old filename and a "New" with the new filename.
  4. I save all files, after which the project file shows up as Modified.
  5. In "Pending Changes" I check the check-all checkbox, write a comment and click the commit button.
  6. Done.

This also works the same when I move files between folders in VS.

I do not quite see where you would have to do a manual git rm or git mv

Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158