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

52,627

Solution 1

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

Solution 2

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".

Solution 3

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.

Solution 4

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

Solution 5

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

Share:
52,627

Related videos on Youtube

FalconNL
Author by

FalconNL

I enjoy applying software solutions to business problems. Having held other commercial positions prior to moving into IT, I find that my empathy with users enables me to span the gap between the business users and the computer environment, and deal with each domain appropriately. It is my view that software should be functional and eminently usable - software should not exist for its own sake. I am interested in well-designed user interfaces. I am interested in the concept of enabling computers to efficiently and effectively support human activity. I am a firm believer in the KISS principle.

Updated on July 05, 2022

Comments

  • FalconNL
    FalconNL 6 months

    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?

    • Keith
      Keith over 10 years
      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.
    • FalconNL
      FalconNL over 10 years
      @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.
    • Keith
      Keith over 10 years
      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.
    • Mario
      Mario almost 10 years
      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
  • James Reed
    James Reed over 11 years
    +1, although I'd add a vote for SourceGear Diffmerge
  • Serj Sagan
    Serj Sagan over 8 years
    C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vsDiffMerge.exe in VS13
  • Serj Sagan
    Serj Sagan over 8 years
    Did not seem to work in VS13...went with WinMerge...that works.
  • Dan Randolph
    Dan Randolph over 7 years
    I used your instructions to replace the compare command with KDiff3 Arguments: %1 %2
  • galaxis
    galaxis over 6 years
    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.
  • Winnemucca
    Winnemucca over 6 years
    Not seeing the IDE on my command prompt. The only thing i see is packages
  • Saturn K almost 6 years
    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.
  • Chait
    Chait over 5 years
    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 for some tips.
  • Scott Langham
    Scott Langham over 5 years
    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.
  • jbyrd
    jbyrd over 5 years
    Thanks for the answer. You might want to update your link to something more recent than a decade old.
  • Brain2000
    Brain2000 about 5 years
    I cannot believe 10 years later and Microsoft still has not added this as a checkbox.
  • Mahen
    Mahen about 5 years
    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
    Mahen about 5 years
    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"
  • tom_mai78101
    tom_mai78101 over 4 years
    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
    tom_mai78101 over 4 years
    Vote here if everyone wanted MS to improve this function. visualstudio.uservoice.com/forums/121579-visual-studio-ide/…
  • vu ledang
    vu ledang over 4 years
    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
  • Polyfun
    Polyfun about 4 years
    This works when comparing files, but does not work when resolving a merge conflict.
  • Elaskanator
    Elaskanator about 3 years
    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 )
  • oligan
    oligan almost 3 years
    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!
  • oligan
    oligan almost 3 years
    In Visual Studio 2019 at least, the toolbar it is in is called "Compare Files".
  • fish-404
    fish-404 over 1 year
    @tom_mai78101 the link not avaliabe now
  • tom_mai78101
    tom_mai78101 over 1 year
    @fish-404 Microsoft closed UserVoice, so you have to submit a feedback from Visual Studio IDE.
  • Kirsan 9 months