84

The compare tool in Visual Source Safe (pre TFS) had a handy checkbox to select "Ignore White Space".

Now we are using TFS with Visual Studio 2010, and the compare dialog no longer has this option. (A ridiculous oversight from Microsoft!)

So, is it possible somehow to work around this?

Bill
  • 3,806
  • 5
  • 33
  • 45
  • 4
    You should be very careful with this option as the TFS merge tool can't tell the difference between white space in code and whitespace in a string literal. A far better solution is to get the entire team to use the same standards for white space in code. – Keith Apr 12 '12 at 13:21
  • 6
    @Keith: The literal issue is handy to know - I hadn't noticed that. However, team standards is not always the issue. If I wrap a block of code in a condition it will automatically indent causing whitespace in front of every row. I only really want to see the If/End statements highlighted as changes, not the whole block in between. – Bill Apr 13 '12 at 03:15
  • 1
    I'd want the opposite - everything in the block highlighted. More importantly it this doesn't just affect the UI highlight, it also changes how the tool actually does merges. Suppose you merge with someone's change - another `If` block that overlaps with your `If` block. If you ignore whitespace you'll get a 'safe' merge (4 single line changes), while if you don't you'll get a conflict to manually fix (2 overlapping blocks). Worst of all - if the former then that code will still compile (it's now a nested `If`) so it won't be obvious that the corrupt merge has messed up both your changes. – Keith Apr 13 '12 at 08:08
  • 1
    I'm on 2012 and can't figure out how to get this to work (diffmerge doesn't exist, I think they are using a new tool). Switching to WinMerge but would be interested if anyone gets this to work of having the option of using the new and improved 2012 tools – Mario Jan 23 '13 at 18:31

6 Answers6

82

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.

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
  • Arguments : %1 %2 %6 %7 %5 /ignorespace

Edit:

Depending on your Visual Studio version and instalation path (x64/x86), the command option may be...

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
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
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. For example, in the VS2015 it will be:

%1 %2 /ignorespace
Jeffrey Drake
  • 805
  • 10
  • 26
Bill
  • 3,806
  • 5
  • 33
  • 45
  • 5
    `C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vsDiffMerge.exe` in VS13 – Serj Sagan Jun 25 '14 at 03:12
  • 3
    Did not seem to work in VS13...went with WinMerge...that works. – Serj Sagan Jun 25 '14 at 03:35
  • I used your instructions to replace the compare command with KDiff3 Arguments: %1 %2 – Dan Randolph Sep 03 '15 at 19:34
  • 1
    Using the above VS2015 cmd line ("ignorespace" or not) doesn't work for me. When in VS, I run a "Compare..." of 2 folders from Source Control Explorer to get folder diffs; in the results, I d-click a single diff it found, it "blinks" as if it did the compare - but doesn't open a tab w/ the results. I tried the "/t" and "/m" args also. – galaxis May 15 '16 at 20:49
  • Not seeing the IDE on my command prompt. The only thing i see is packages – Winnemucca Sep 07 '16 at 15:16
  • The Command section refers to Program Files when it should be Program Files (x86), because the VS IDE is not, and will never be 64 bit. – Saturn K Jan 23 '17 at 21:29
  • I cannot believe 10 years later and Microsoft still has not added this as a checkbox. – Brain2000 Oct 27 '17 at 18:12
  • 6
    This solution no longer works in VS2017. The same Ignore Space option is made available via the Tools menu (as answered below), but MS has change the meaning to only ignore at the beginning or end of line. Even the menu option is called "Ignore Trim WhiteSpace" – Mahen Nov 03 '17 at 13:44
  • Vote here if everyone wanted MS to improve this function. https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/33046552-improve-compare-tool-ignore-trim-whitespace-opti – tom_mai78101 Jun 01 '18 at 19:37
  • @tom_mai78101 the link not avaliabe now – Jun Yu Jun 01 '21 at 09:11
  • @fish-404 Microsoft closed UserVoice, so you have to submit a feedback from Visual Studio IDE. – tom_mai78101 Jun 03 '21 at 21:47
  • Found this https://developercommunity.visualstudio.com/t/Ignore-whitespace-changes-option-in-di/1069606 to vote. – Kirsan Mar 13 '22 at 21:38
  • **VS2022:** - professional C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\vsDiffMerge.exe – Aggie Jon of 87 Jan 05 '23 at 17:01
  • **VS2019:** - C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\vsDiffMerge.exe The pattern for these is fairly standard. **FUN NOTE** - I use both 19 and 22 currently. I accidentally put the 2022 file link in the 2019 tool window. When I ran the compare in 2019 it opened the VS 2022 tool to actually do the compare. – Aggie Jon of 87 Jan 05 '23 at 18:07
41

There is a "=" button on Visual Studio 2017 toolbar that helps to compare files as you want. Hope this screenshot will help.

Screenshot ofVisual Studio 2017 toolbar. The button with the equal sign is on the right, next to the lock icon. The tooltip for the button states "Ignore trim whitespace Ctrl+\, Ctrl+Space".

BSMP
  • 4,596
  • 8
  • 33
  • 44
Master
  • 510
  • 4
  • 7
  • 6
    This works for white space at the beginning or end of lines, but not in the middle of text. So in my case it is quite useless. – Mahen Nov 03 '17 at 13:35
  • It works, Since visual studio replaces tab by space and vice versa when we use hotkey to format codes. So when we review codes, we see that changes which 's so embarrassing – vu ledang Sep 13 '18 at 04:46
  • This answer helped me not only with my current problem, but also alerted me to "auto-synchronize views", which'll help when I'm doing big merges. Thanks for this! – Andrew Grimm Mar 05 '20 at 00:12
  • 1
    In Visual Studio 2019 at least, the toolbar it is in is called "Compare Files". – Andrew Grimm Mar 06 '20 at 00:07
11

The default diff tool in Visual Studio is extremely annoying. I suggest you use an alternative. WinMerge is my favourite. It also has an option to ignore whitespace (menu Edit -> Options -> Compare -> Ignore all (under the groupbox "Whitespace" at the top)).

See Using WinMerge with TFS.

Lennart
  • 9,657
  • 16
  • 68
  • 84
e-mre
  • 3,305
  • 3
  • 30
  • 46
6

In VS2015 it's possible to "ignore white space" when comparing clicking a little icon with the = symbol.
Go to "View/Toolbars/Compare Files". 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. 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. 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. And in VS Options > Source Control > Subversion Environment, I have this:

enter image description here

enter image description here

Luis Hernandez
  • 453
  • 5
  • 8
  • Hello, and welcome to StackOverflow. While this answer provides a solution to the problem, it is better to provide some explanation. Please take a look [here](http://stackoverflow.com/help/how-to-answer) for some tips. – Chait Mar 30 '17 at 23:17
  • I thought this was going to solve my problems, but I realize I already have ignore whitespace enabled. The built in diff tool is not very smart though, there are loads of whitespace changes that it seems to think are not whitespace changes. – Scott Langham Jun 02 '17 at 14:26
  • 1
    This works when comparing files, but does not work when resolving a merge conflict. – Polyfun Nov 27 '18 at 16:43
5

The default diff tool in VS 2013 does let you ignore whitespace after all. 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. 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 toolbar button for ignoring whitespace

Jim Black
  • 109
  • 1
  • 6
  • 5
    In Visual Studio 2017 15.7.1, in the answer's icon's place, the new icon looks like a small equal sign. – tom_mai78101 May 11 '18 at 18:21
  • 1
    This only works for whitespace at the front or end of a line (hence the name *trim* whitespace), not in the middle. So `asdf(qwerty)` is marked as different from `asdf ( qwerty )` – Elaskanator Oct 29 '19 at 21:49
4

in VS 2012, this might be what you're looking for with no changes to Diff tool.

Opening up the compare screen in VS 2012 and at the top you see the following option in the toolbar. as it might be the same comparison as user: Master screenshot.

enter image description here

Michael Edmison
  • 663
  • 6
  • 14