我们使用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内部进行重构时,会发生很多这样的重命名,即,对类/成员/etc进行了重命名,而所有引用都进行了更改。如果 namespace 或类名更改,则文件将被重命名。

因此,是否有任何设置需要切换,是否要安装任何工具,是否需要安抚,以便将Visual Studio中的重命名也映射为重命名为GIT(就像git mv一样使它平滑)?

最佳答案

核心git(命令行应用程序)仅通过检测重命名为暂存的文件和暂定为删除的文件之间的重命名来识别重命名。

但是,Visual Studio不会暂存您在操作过程中所做的更改。相反,它将在提交时分阶段进行更改。造成这种情况的原因有很多,但主要的原因是,进行更改会将文件放置在对象数据库中,并且每次保存都将花费巨大的成本。

您将需要使用git addgit rm手动暂存更改,通过将添加的更改与重命名的更改进行比较,您的重命名将一如既往地被报告。

(请注意,Visual Studio –因为它不会随即进行更改,因此会同时检查已暂存和未暂存的文件以进行重命名检测。因此,Visual Studio将在核心git之前报告重命名。但是,当状态更改时,它们应在状态中显示相同的结果您进行这些更改。)

关于git - 在Visual Studio(2013)中将文件重命名传播为GIT,就像将GIT重命名一样吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21679182/

10-14 17:48