VS Code: How to Compare Two Files (Find the Difference)

Last updated on September 23, 2021 A Goodman Loading... Post a comment

This article shows you a couple of different ways to compare two files by using VS Code (Visual Studio Code). The first approach is to use your mouse and the second one is to use the command line.

Using Your Mouse

1. Select the two files you want to compare (see the diff), right-click, and select “Compare Selected” from the drop-down menu.

2. The difference will be highlighted as below:

Demo:

Using Command Line

The command that can be used to check the diff between two files:

code --diff [path to file 1] [path to file 2]

When you run the command above, you may run into this error:

command not found: code

Solution: Open Command Palette (press “Command” + “Shift” + “P” on Mac and “Ctrl” + “Shift” + “P” on Windows), search for “install code” and select “Shell Command: Install ‘code’ command in PATH”:

And you will see this:

Example:

code --diff ./lib/main.dart ./lib/draft.dart

The result:

Conclusion

We’ve gone through two different ways to check the difference between two files by using VS Code. If you’d like to explore more about this awesome IDE, take a look at the following articles:

You can also check our VS Code topic page for the latest guides, tips, and tricks.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles