Comapare Files (1), With TFS And Git GUI In Visual Studio

One usually has the need to compare two files or two folders, or two branches, especially as a frequent user of Visual Studio, one hopes to find a way to use Visual Studio to complete the comparison job in Visual Studio with somewhat the way like Source Control or Version Control software for comparison.

This article will cover this topic and related issues (we use the current version of 2019 16.11.0).

It seems this article is a little bit too long, I split it into two: one with native Visual Studio Tool, another is Visual Studio with Extension or Non-Visual Studio.

After splitting the article into two, they are still too long, I split it as three:

Introduction

Contents of this article series,

  • Compare Files (1),  with TFS and Git GUI in Visual Studio
    • TFS
    • Git
  • Compare Files (2),  with Visual Studio Built-in Tool
    • Command-line in Visual Studio
    • Visual Studio Developer Command Prompt 
    • Windows Prompt
  • Compare Files (3),  with Visual Studio Extension or Non-Visual Studio Apps
    • A: Tools outside of Visual Studio for Files Comparison
      • Online comparison, such as diff
      • Other Applications, such as VS Code or Word
    • B: Visual Studio Extention for Comparison Tools from Third Parties:
      • Code Compare in Visual Studio --- devart.com
      • Compare Files VS2019 --- marketplace.visualstudio.com

The Visual Studio only supports the GUI Compare Files feature to TFS or Git, the source control tools.  We will discuss these features in the first article of this article series; and then as an alternative, we invoke the Visual Studio built-in Comparison Tools from the command line that we will discuss in the second article in this article series; and finally, we discuss the alternative ways to compare files without Visual Studio in the third article.

Compare Files (1),  with TFS and Git GUI in Visual Studio
 

1, Under the Environment of TFS

We can compare any two files using the Compare dialog [Microsoft]. Under the environment of TFS:

On the menu bar, choose ViewOther Windows => Source Control Explorer.

In Source Control Explorer, right-click a file and select Compare.

Comapare Files (1),  with TFS and Git GUI in Visual Studio

The Compare dialog box is opened,

At this point, we can choose any different two files, two folders, two versions of branches into the Source Path and the Target Path for the comparison. If you choose a folder to right-click to get the Compare dialog box, then further choices for View Options will be shown, you can choose whatever you like. In the case of the default, the Compare Dialog window will show all files or folders compared, such as.

Click the different files in Red, then you will get the two files comparison,

2, Under the Environment of Git

This is a huge topic, setting up the environment of Git might be worth getting a Microsoft Certificate or two or several. We just mention an example using Git to compare two files. Assume we have used Git repository to handle source control, Right Click any file under Git => Git, you will see a subcommand: Compare with Unmodified, for this checked-in file, this command is gray out.

If you make any modification for the checked-in file, that file would be checked out, then Right Click the file again => Git => Compare with Unmodified.

Then you will get the two files, the modified file in your local folder and the unmodified file in Git,  for comparison.

At this point, in general, for any two files, you can add one file into Git (checked-in), and then modify the file locally by another file, then make the comparison. i.e., Using Git, you can compare any two files, but with some complexity, so we just say the topic a little bit like this. 

Summary

In this article, we discussed the features to compare files, folders, or branches with Visual Studio GUI under environments under source controls of TFS or Git, especially the way from TFS can be used for any file, folder, branches comparison.

The disadvantage of these methods, they only are available under the source control environment of TFS or Git.

Reference