简体   繁体   English

在 Visual Studio / TFS 中比较源代码时如何忽略空格?

[英]How to ignore white space when comparing source in Visual Studio / TFS?

The compare tool in Visual Source Safe (pre TFS) had a handy checkbox to select "Ignore White Space". Visual Source Safe(前 TFS)中的比较工具有一个方便的复选框,用于 select“忽略空白”。

Now we are using TFS with Visual Studio 2010, and the compare dialog no longer has this option.现在我们在 Visual Studio 2010 中使用 TFS,比较对话框不再有这个选项。 (A ridiculous oversight from Microsoft!) (微软的一个荒谬的疏忽!)

So, is it possible somehow to work around this?那么,是否有可能以某种方式解决这个问题?

This is a workaround that seems to get around the problem.这是一种似乎可以解决问题的解决方法。

In Visual Studio, select Tools / Options / Source Control / Visual Studio Team Foundation System and click the Configure User Tools button.在 Visual Studio 中,select Tools / Options / Source Control / Visual Studio Team Foundation System 并单击配置用户工具按钮。

In the dialog, Add an item with the following settings.在对话框中,添加具有以下设置的项目。

  • Extension: .*扩大: 。*
  • Operation: Compare操作:比较
  • Command: C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe命令:C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe
  • Arguments: %1 %2 %6 %7 %5 /ignorespace Arguments: %1 %2 %6 %7 %5 /忽略空间

Edit:编辑:

Depending on your Visual Studio version and instalation path (x64/x86), the command option may be...根据您的Visual Studio 版本安装路径(x64/x86),命令选项可能是...

VS2010: C:\Program Files (x86) \Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe VS2010: C:\Program Files (x86) \Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe
VS2012: C:\Program Files (x86) \Microsoft Visual Studio 11.0\Common7\IDE\diffmerge.exe VS2012: C:\Program Files (x86) \Microsoft Visual Studio 11.0\Common7\IDE\diffmerge.exe
VS2013: C:\Program Files (x86) \Microsoft Visual Studio 12.0\Common7\IDE\vsDiffMerge.exe VS2013: C:\Program Files (x86) \Microsoft Visual Studio 12.0\Common7\IDE\vsDiffMerge.exe
VS2015: C:\Program Files (x86) \Microsoft Visual Studio 14.0\Common7\IDE\vsDiffMerge.exe VS2015: C:\Program Files (x86) \Microsoft Visual Studio 14.0\Common7\IDE\vsDiffMerge.exe
VS2017: C:\Program Files (x86) \Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\vsDiffMerge.exe VS2017: C:\Program Files (x86) \Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\vsDiffMerge.exe

In the argument option leave it with the same number of arguments as the VS suggests and just add /ignorespace in the end.在参数选项中,保留与 VS 建议的相同数量的 arguments 并在最后添加 /ignorespace。 For example, in the VS2015 it will be:例如,在 VS2015 中它将是:

%1 %2 /ignorespace

There is a "=" button on Visual Studio 2017 toolbar that helps to compare files as you want. Visual Studio 2017 工具栏上有一个“=”按钮,可帮助您根据需要比较文件。 Hope this screenshot will help.希望这个截图会有所帮助。

Visual Studio 2017 工具栏的屏幕截图。带有等号的按钮位于右侧,靠近锁定图标。该按钮的工具提示状态为“忽略修剪空白 Ctrl+\、Ctrl+Space”。

The default diff tool in Visual Studio is extremely annoying. Visual Studio 中的默认差异工具非常烦人。 I suggest you use an alternative.我建议您使用替代方法。 WinMerge is my favourite. WinMerge 是我的最爱。 It also has an option to ignore whitespace (menu Edit -> Options -> Compare -> Ignore all (under the groupbox "Whitespace" at the top)).它还有一个忽略空白的选项(菜单编辑->选项->比较->全部忽略(在顶部的组框“空白”下))。

SeeUsing WinMerge with TFS .请参阅将 WinMerge 与 TFS 一起使用

In VS2015 it's possible to "ignore white space" when comparing clicking a little icon with the = symbol.在 VS2015 中,将单击小图标与=符号进行比较时,可以“忽略空白”。
Go to "View/Toolbars/Compare Files". Go 到“查看/工具栏/比较文件”。 In the toolbar click on "Ignore trim whitespace".在工具栏中单击“忽略修剪空白”。

Update 2020 : we struggled a lot solving conflicts with VS comparison tool and the Tortoise SVN one, so after a research we decided to install Devart Code Compare (free version) which has integration with VS2015/2017/2019, SVN (Tortoise and Ankh), TFS, Mercurial, GIT, etc. and Windows Explorer, so no more nightmares/confusion between different comparisons tools. 2020 年更新:我们在解决与 VS 比较工具和 Tortoise SVN 的冲突时遇到了很多困难,因此经过研究,我们决定安装与 VS2015/2017/2019、SVN (Tortoise) 集成的Devart Code Compare (免费版) , TFS, Mercurial, GIT, etc. 和 ZAEA23489CE3AA9B60Z 不同的比较工具之间的比较,所以没有/4 更多。 Give it a try, it's extremely useful.试试看,非常好用。 It has also Merge to solve conflicts and Folder diff, which is really useful when SVN does not merge for some reason.它还具有解决冲突和文件夹差异的合并,当 SVN 由于某种原因没有合并时,这非常有用。 Also, clicking on the left/right arrows to copy the changes is a feature that I really like.此外,单击左/右箭头以复制更改是我非常喜欢的功能。

Below VS image is from Devart website, but in my case I setup Code Compare to open it outside VS instead of embedded, I think it behaves better.下面的 VS 图像来自 Devart 网站,但在我的情况下,我设置 Code Compare 以在 VS 外部打开它而不是嵌入,我认为它的表现更好。 And in VS Options > Source Control > Subversion Environment , I have this:在 VS Options > Source Control > Subversion Environment ,我有这个:

在此处输入图像描述

在此处输入图像描述

in VS 2012, this might be what you're looking for with no changes to Diff tool.在 VS 2012 中,这可能是您正在寻找的内容,而无需更改 Diff 工具。

Opening up the compare screen in VS 2012 and at the top you see the following option in the toolbar.在 VS 2012 中打开比较屏幕,您会在顶部的工具栏中看到以下选项。 as it might be the same comparison as user: Master screenshot.因为它可能与用户相同的比较:主屏幕截图。

在此处输入图像描述

The default diff tool in VS 2013 does let you ignore whitespace after all.毕竟,VS 2013 中的默认差异工具确实可以让您忽略空格。 Just run the standard differencing process.只需运行标准差分过程。 When Visual Studio brings up the differences, look on the toolbar, where you will see an icon that looks like a document with 5 dots under it, as shown below.当 Visual Studio 显示差异时,查看工具栏上的图标,您将在其中看到一个看起来像文档的图标,其下方有 5 个点,如下所示。 This button toggles whether the displayed differences ignore white space.此按钮切换显示的差异是否忽略空白。 This worked well enough for me;这对我来说已经足够好了; I wanted it to ignore changes in the white space caused by indentation.我希望它忽略由缩进引起的空白区域的变化。 用于忽略空格的 VS 2013 工具栏按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM