使用 Visual Studio 的 git 分支之间的差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37052450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:09:29  来源:igfitidea点击:

Differences between git branches using Visual Studio

gitvisual-studio-2015

提问by Rotem B

I'm trying to understand how to compare branches or commits using VS 2015.

我试图了解如何使用 VS 2015 比较分支或提交。

Using other Git programs, I can easily compare versions, but I can't see how it's done in VS.

使用其他 Git 程序,我可以轻松比较版本,但在 VS 中我看不到它是如何完成的。

Can anyone help?

任何人都可以帮忙吗?

采纳答案by peekama

I just spent a bit of time playing with the current version of VSTS and figured it out (as of October 2016):

我只是花了一些时间玩当前版本的 VSTS 并弄明白了(截至 2016 年 10 月):

  1. Go to Code -> Branches
  2. Click on the commit diff count to the right of the updated date as in this screenshot: vsts_screenshot
  1. 转到代码 -> 分支
  2. 单击更新日期右侧的提交差异计数,如下面的屏幕截图所示: vsts_screenshot

This will take you to a page that shows both a commit difference between the two, and a file comparison

这将带您进入一个页面,其中显示了两者之间的提交差异和文件比较

回答by Flandraco

To compare a specific object (solution, project, source file,...) in Microsoft Visual Studio (using MVS2015):

要在 Microsoft Visual Studio(使用 MVS2015)中比较特定对象(解决方案、项目、源文件...):

  1. Locate the object in the Solution Explorer, and bring up the context menu (right-click): select "View History...". This brings up the History window for this object, with all the commits where the object changed(from any branch).
  2. Multi-select the two commits that you want to compare (left-click on the first one, Ctrl-left-click on the second one).
  3. Now bring up the context menu on either of the selected commits (right_click): select "Compare...". This brings up the Diff window for the object in the respective commits (with the differences highlighted in red -lines removed from first commit- or green -lines added in second commit). You can use the scroll bar in the Diff window, or the "Previous Difference" and "Next Difference" button in the ribbon to go between the differences of the object.
  1. 在解决方案资源管理器中找到对象,并调出上下文菜单(右键单击):选择“查看历史记录...”。这将打开此对象的历史记录窗口,其中包含对象更改的所有提交(来自任何分支)。
  2. 多选要比较的两个提交(左键单击第一个,Ctrl-左键单击第二个)。
  3. 现在调出任一选定提交的上下文菜单(右键单击):选择“比较...”。这会为各个提交中的对象打开 Diff 窗口(红色线中突出显示的差异从第一次提交中删除,或在第二次提交中添加的绿色线中)。您可以使用“差异”窗口中的滚动条,或功能区中的“上一个差异”和“下一个差异”按钮来查看对象的差异。

I am not sure that there is a way to compare ALL the items in two different commits (I just invoke GitKraken -free for non-commercial purposes- or any other GUI for git on my local repo). Gitkraken is amazingly simple though: select any two commits, and all the differences between those commits are available at your fingertips.

我不确定是否有一种方法可以比较两个不同提交中的所有项目(我只是调用 GitKraken - 免费用于非商业目的 - 或在我的本地存储库中为 git 调用任何其他 GUI)。不过 Gitkraken 非常简单:选择任意两个提交,这些提交之间的所有差异都触手可及。

回答by rajeemcariazo

As of October 2017, when you right click on a branch under Code->Branches, you will get this menu. Click on compare branches.

截至 2017 年 10 月,当您右键单击 Code->Branches 下的一个分支时,您将获得此菜单。单击比较分支。

enter image description here

在此处输入图片说明