Which method, when
| You have | Use | One line |
|---|---|---|
| Two files on Linux or macOS | diff | diff -u a b |
| Two files on Windows | fc / PowerShell | fc /N a b |
| Files open in an editor | VS Code or Notepad++ | Select for Compare · Alt+D |
| Versions in a repository | git diff | git diff main..feature -- file |
| Two folders | diff -rq / robocopy /L | diff -rq dirA dirB |
| Two texts from anywhere | Online diff checker | Paste, Compare |
Step-by-step guides
How to Diff Two Files in Linux
Compare two files from the Linux or macOS terminal with diff: unified output, side-by-side view, ignoring whitespace, colour, and how to read the result.
Read the guide →How to Compare Two Files in VS Code
Compare two files in Visual Studio Code without an extension: Select for Compare, Ctrl+click, the command palette, the clipboard, and code --diff.
Read the guide →How to Compare Two Files in Windows
Compare two files on Windows with what is already installed: the fc command, PowerShell Compare-Object, and free tools such as WinMerge and VS Code.
Read the guide →How to Diff Two Files with Git
Use git diff to compare two files: working copy against a commit, one file between two branches, any two files with --no-index, word diffs and difftool.
Read the guide →How to Compare Two Files in Notepad++
Install the ComparePlus plugin from Plugins Admin, compare the two open tabs with Ctrl+Alt+C, read the colours, navigate changes, and handle moved lines.
Read the guide →How to Compare Two Folders
Find which files differ between two directories: diff -rq and rsync dry runs on Linux and macOS, robocopy /L and WinMerge on Windows, meld for a visual view.
Read the guide →Reading a diff
Whatever produced it, a diff answers one question: what would I change in the first file to get the second? Unified format, the one Git and most tools print, marks removed lines with a minus and added lines with a plus, with a few unchanged lines around them for context and an @@ header giving the line numbers. Changed lines appear as a removal followed by an addition. Once you can read that, every tool on this page is the same tool with a different front door.
FAQ
What is the quickest way to compare two files?
If they are on your machine: diff -u a b on Linux or macOS, fc a b on Windows, or select both in VS Code and choose Compare Selected. If they are two pieces of text in front of you, paste them into the online diff checker.
What do the symbols in a diff mean?
In unified diffs a minus marks a line removed from the first file and a plus a line added in the second; @@ headers give line numbers. Classic diff uses < and > for the same idea, and letters a, c and d for added, changed and deleted.
How do I compare two files without installing anything?
Use the online diff checker on this site: paste each file's contents and press Compare. The comparison runs in your browser; nothing is uploaded.
Can I compare two files on different computers?
Copy one file across, or paste both contents into the online checker and share the result as an expiring link with Log Share.
Two texts in front of you right now? Compare them online, in your browser.