Sublime Text - How to Compare Two Files

We have all been in a situation where we need to compare the difference between code in two files. Today we will take a look at the diff functionality available in Sublime Text to help us find changes between two different files.

 

Native File Comparison

Sublime Text 3 actually has a diff function built right into it. To use it open your project files by pressing command + o (CTRL on Windows) and opening the directory containing your project files. Alternatively, you can choose file > open from the main menu.

 

Open Sublime Project

 

Next, select the two files you wish to compare by holding down command (CTRL on Windows) and clicking each file once. It doesn't matter where each file is within the project directory structure so long as you can see the files to select them.

 

The first one you select will be considered the "old" version of the file.

 

Then right-click on one of the selected files and choose "Diff Files" from the dialogue menu.

 

Open diff Sublime

 

A new tab will open in Sublime containing the file differences on a line-by-line basis. If there are no differences nothing will be highlighted.

 

 

Compare Side-By-Side Package

If you are looking for side-by-side file comparisons you can install the Compare Side-By-Side Package using the Sublime Text Package Manager.

 

Once this is installed, right-click on the file tab item and click "Compare With". Once you have selected a file for comparison a new Sublime Text window will appear showing a side-by-side file comparison.

 

Compare side-by-side Sublime

 

Conclusion

Now have the ability to quickly compare files in two different ways using Sublime Text.

sublime edtior file text