【发布时间】:2014-02-10 03:55:56
【问题描述】:
我们使用 GIT 和 Visual Studio 2013(终极版 + 专业版)。解决方案和项目的代码在 GIT 中,每当我们在 Visual Studio 中重命名文件时,GIT 都会将它们视为
重命名前
c:\temp\testCodeSnippets>git status
# On branch master
nothing to commit (working directory clean)
重命名后(来自 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")
通过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
#
基本上,在 VS 中执行的重命名仍然需要一些手动工作。同样重要;很多这些重命名发生在从 IDE 内部重构时,即类/成员/等被重命名并且所有引用都得到更改。如果命名空间或类名更改,文件将被重命名。
那么,是否有任何设置可以切换、任何工具要安装、任何神明可以安抚,以便从 Visual Studio 中的重命名也映射为 GIT 的重命名(就像 git mv 可以使其顺利进行)?
【问题讨论】:
-
AFAIK add+remove 相当于 git 中的重命名/移动。它会自动计算出你做了什么。这是它优于 svn 的一大优势,后者需要显式跟踪重命名。
-
Visual Studio 使用与 git 相同的启发式方法来检测重命名。您是否看到
git status将这些项目报告为重命名但 Visual Studio 没有?您能否展示提供更多详细信息的文件和一些屏幕截图? -
@EdwardThomson:我们没有使用 VS 进行 git 状态报告。我们使用 git (bash) 或 Tortoise Git 与 git 交互,但用于开发/重构等。
-
我明白了;正如其他人指出的那样,Git 中没有“重命名”,而是查看添加和删除文件之间的相似性,并建议重命名发生在
git status或git diff中。 Visual Studio 不会更改此行为,它只是没有暂存更改。
标签: git visual-studio