Back to blog
How to compare two text files and find the differences

How to compare two text files and find the differences

Compare two versions of text or code and see what changed with a free online diff checker, VS Code, the diff, fc or git commands, or Microsoft Word.

By SpeedyTools TeamNovember 5, 20266 min read

You have two versions of a document, a config file or some code, and you need to know what changed between them. Comparing them by eye misses changes. A diff tool compares them line by line and highlights every addition and deletion.

Quick answer

Paste both versions into an online diff checker. Removed lines show in red and added lines in green, and you can switch to word-level or character-level comparison to see exactly what changed in a line. For files already on your computer, diff on macOS and Linux or fc on Windows work from the terminal.

1. Use an online diff checker

The SpeedyTools diff checker runs in your browser and never sends the text you paste to a server. Here's how to use it:

  1. Paste the older version into Original and the newer one into Modified, or load each file with the upload button.
  2. Read the result. Removed lines start with a minus sign and show in red, added lines start with a plus sign and show in green.
  3. Change Compare to Words or Characters when one long line changed and you need to see where.
  4. Copy the result or download it as a .txt file.

It treats everything as plain text, so prose, CSV, JSON, YAML and any programming language all work. It doesn't have ignore-whitespace or ignore-case options, so changed indentation counts as a difference. It does normalise Windows and Unix line endings, so a file saved on another operating system doesn't show every line as changed.

2. Compare files in VS Code

In VS Code's Explorer, right-click the first file and choose Select for Compare, then right-click the second file and choose Compare with Selected. From a terminal, code --diff old.txt new.txt does the same thing. VS Code shows the two files side by side with syntax highlighting, which suits large code files.

3. Compare from the command line

  • macOS and Linux. diff -u old.txt new.txt prints a unified diff. Add -w to ignore whitespace, or -i to ignore case.
  • Anywhere git is installed. git diff --no-index old.txt new.txt gives a coloured diff, even outside a repository. Add --word-diff for word-level changes.
  • Windows. Run fc old.txt new.txt in Command Prompt, or Compare-Object (Get-Content old.txt) (Get-Content new.txt) in PowerShell.

Use the command line when you need a patch for git apply or patch. The online tool's output is a readable change list without the headers a patch file needs.

4. Compare Word documents

For .docx files, Microsoft Word's Review > Compare > Compare builds a third document with every change shown as tracked changes, including formatting changes. To compare only the words, copy the text from each document into a diff checker.

Reading a diff

  • A whole block marked removed and added again usually means its indentation or line endings changed, not its content.
  • The last line marked as changed often means one file ends with a newline and the other doesn't.
  • Moved paragraphs show as a deletion in one place and an addition in another. Line diffs don't detect moves.

Written by the SpeedyTools team

A small team of software engineers who build and maintain the free tools on this site. Learn more about us.

Frequently asked questions

What is the easiest way to compare two texts?

Paste both versions into an online diff checker. It highlights removed lines in red and added lines in green straight away, with nothing to install.

How do I compare two files in Windows without extra software?

Run fc file1.txt file2.txt in Command Prompt, or Compare-Object (Get-Content file1.txt) (Get-Content file2.txt) in PowerShell. Both list the lines that differ.

Can I ignore whitespace when comparing?

On the command line, diff -w and git diff -w ignore whitespace. VS Code has a setting to ignore leading and trailing whitespace. The SpeedyTools diff checker has no ignore options.

Is it safe to paste confidential text into a diff checker?

Use one that runs in your browser. The SpeedyTools diff checker compares text in your browser tab and never sends it to a server.

Related posts