【问题标题】:Propogate file renames in Visual Studio (2013) to GIT as GIT renames?将 Visual Studio (2013) 中的文件重命名传播到 GIT 作为 GIT 重命名?
【发布时间】: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 statusgit diff 中。 Visual Studio 不会更改此行为,它只是没有暂存更改。

标签: git visual-studio


【解决方案1】:

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

但是,Visual Studio 不会暂存您在操作期间所做的更改。相反,它将在提交时暂存更改。这有几个原因,但主要是暂存更改会将文件放置在对象数据库中,并且每次保存都这样做会非常昂贵。

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

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

【讨论】:

    猜你喜欢
    • 2011-04-24
    • 2011-12-07
    • 2016-04-15
    • 2015-08-15
    • 1970-01-01
    • 2015-07-16
    • 2011-02-11
    • 1970-01-01
    相关资源
    最近更新 更多