12 min read

How to Compare Text Files: Best Free Diff Tools

Find every difference between two files in seconds. Learn how diff algorithms work, how to read diff output, and which free tools are best for code, content, and configuration files.

When You Need Text Comparison

Text comparison is one of those tasks you do not think about until you need it urgently. Then you need it immediately, and you need it to be reliable. Here are the most common scenarios where diff tools save hours of manual inspection.

Code reviews

Every pull request is a diff. When you review code, you are comparing the current version against the proposed changes and checking for bugs, style issues, and logic errors. A good diff view makes this fast. A bad one makes it a chore.

Content editing

Writers, translators, and content teams need to see exactly what changed between document versions. Did the editor remove a paragraph? Change a number? Rephrase a legal clause? A word-level diff answers these questions in seconds.

Configuration debugging

When a deployment breaks, comparing the current configuration file against the last working version is often the fastest path to a fix. One missing line in an Nginx config, one changed environment variable, one extra comma in a JSON file -- diff catches it.

Database migrations

Comparing SQL schema dumps before and after a migration verifies that the migration did exactly what it was supposed to and nothing more. No accidental dropped columns, no missing indexes.

Security auditing

Comparing file hashes and content across deployments detects unauthorized changes. If a file on your production server differs from the version in your repository, something went wrong -- and a diff tool tells you exactly what.

The QTool Diff Checker handles all of these scenarios. Paste two blocks of text, click compare, and see every difference highlighted inline. No signup, no file uploads, no data sent to any server.

Types of Diff Algorithms

Not all diff tools compare text the same way. The algorithm determines what counts as a "difference" and how it is displayed.

Line-based diff

The most common approach. Line-based diff compares text one line at a time. If any character on a line changes, the entire line is marked as modified. This is the algorithm behind git diff, the Unix diff command, and most code review tools.

Best for: Source code, configuration files, and any content where lines are meaningful units.

- const API_URL = "https://api.example.com/v1";
+ const API_URL = "https://api.example.com/v2";

In line-based diff, the entire line is highlighted even though only v1 changed to v2. Some tools add word-level highlighting within the changed lines to make the actual change easier to spot.

Word-based diff

Word-based diff breaks each line into words and compares them individually. Only the changed words are highlighted, not the entire line. This is significantly more useful for prose, documentation, and any text where changes are scattered within paragraphs.

The API supports GET and POST requests.
The API supports GET, PUT, and POST requests.

Best for: Documentation, blog posts, legal text, and any content written in natural language.

Character-based diff

Character-based diff compares text one character at a time. This is the most granular level and highlights exact character-level differences -- useful for catching encoding issues, invisible characters, and typos in strings that look identical.

Best for: Debugging encoding problems, comparing URLs, and verifying hashes or tokens.

Semantic diff

Semantic diff understands the structure of the content it is comparing. A JSON-aware diff knows that {"a":1,"b":2} and {"b":2,"a":1} are equivalent. An HTML-aware diff ignores whitespace differences between tags. These tools are specialized but powerful for their domains.

Algorithm Granularity Best For Example Tool
Line-basedWhole linesCode, config filesgit diff, diff
Word-basedIndividual wordsProse, documentationQTool Diff Checker, Meld
Character-basedSingle charactersEncoding, hashesQTool Text Diff
SemanticStructuralJSON, HTML, XMLjson-diff, html-differ

How to Read Diff Output

Understanding diff output is a core developer skill. Here is how to read the most common format: unified diff (used by git diff).

--- a/config.json
+++ b/config.json
@@ -3,7 +3,8 @@
   "database": {
     "host": "localhost",
     "port": 5432,
-    "name": "myapp_dev",
-    "pool_size": 5
+    "name": "myapp_production",
+    "pool_size": 20,
+    "ssl": true
   }
 }

Reading the header

Reading the changes

In the example above, "name" changed from myapp_dev to myapp_production, pool_size changed from 5 to 20, and a new "ssl": true line was added.

Quick Reference

- = removed (red), + = added (green), no prefix = unchanged. Modified lines appear as a removal followed by an addition. This format is universal across Git, GitHub, GitLab, and most diff tools.

Command-Line Diff Tools

The command line remains the fastest way to compare files for developers who live in the terminal.

Basic diff (built-in)

# Standard unified diff
diff -u file1.txt file2.txt

# Side-by-side comparison
diff -y --width=120 file1.txt file2.txt

# Compare directories recursively
diff -r --brief dir1/ dir2/

# Ignore whitespace differences
diff -u -w file1.txt file2.txt

Git diff (best for developers)

# Compare any two files (even outside a Git repo)
git diff --no-index file1.txt file2.txt

# Word-level highlighting within changed lines
git diff --word-diff file1.txt file2.txt

# Stat summary (files changed, insertions, deletions)
git diff --stat HEAD~5

# Show only file names that changed
git diff --name-only HEAD~1

Modern alternatives

# delta - beautiful diff output with syntax highlighting
# Install: brew install git-delta (macOS) / cargo install git-delta
git diff | delta

# difft (difftastic) - structural diff that understands syntax
# Install: brew install difftastic
difft file1.js file2.js

For verifying file integrity before and after transfers, generate checksums with the Hash Generator. If the hashes differ, you know the files changed -- then use a diff tool to find exactly what.

Best Free Diff Tools Compared

Tool Type Diff Modes Best For
QTool Diff Checker Browser Line, word, inline, side-by-side Quick comparison with zero setup
QTool Text Diff Browser Character-level, word-level Granular character-level differences
VS Code (built-in) Editor Line, inline, side-by-side Comparing files in your project
Meld Desktop Line, word, three-way merge Visual merging on Linux/Windows
Kaleidoscope Desktop Text, image, folder Premium experience on macOS
delta CLI Line, word, syntax-highlighted Beautiful terminal diff output
difftastic CLI Structural (AST-aware) Language-aware code comparison

For most ad-hoc comparisons -- checking what changed in a config file, spotting differences between two API responses, verifying a document edit -- a browser-based tool is the fastest path. No installation, no file system navigation, no terminal commands. Paste, compare, done.

Compare Text Instantly

Paste two versions of any text and see every difference highlighted. Line-level, word-level, and side-by-side views. No signup, no data leaves your browser.

Open Diff Checker

Comparing JSON Files

JSON files are especially tricky to diff because minor formatting differences (extra spaces, different key ordering) can make two semantically identical files look completely different in a line-based diff.

Step 1: Format both files

Before comparing, normalize both JSON files with a formatter. This ensures consistent indentation, key ordering, and line breaks. Use the QTool JSON Formatter to pretty-print both files, then paste the formatted output into the Diff Checker.

Step 2: Compare with structure awareness

# Command-line: jq normalizes JSON before diffing
diff <(jq --sort-keys . file1.json) <(jq --sort-keys . file2.json)

# Or with git diff for colored output
git diff --no-index <(jq -S . file1.json) <(jq -S . file2.json)

The jq --sort-keys flag sorts all object keys alphabetically before comparison, which eliminates false positives from key reordering.

Step 3: For deep comparison, use json-diff

# Install: npm install -g json-diff
json-diff file1.json file2.json

# Output shows only actual value differences:
#  {
#    "database": {
# -    "host": "localhost"
# +    "host": "db.production.internal"
#    }
#  }

For merging changes from two different JSON edits, the Text Diff Merger can help reconcile conflicting modifications.

Three-Way Merge

A three-way merge compares three versions of a file: the base (common ancestor), yours (your changes), and theirs (someone else's changes). This is what happens during a Git merge conflict.

# Configure a visual merge tool in Git
git config --global merge.tool meld    # or vimdiff, opendiff, kdiff3
git config --global mergetool.prompt false

# When a merge conflict occurs:
git merge feature-branch
# CONFLICT in config.json
git mergetool    # Opens the configured visual merge tool

In a three-way merge view:

For each conflict, you choose which side's changes to keep -- or manually edit the center panel to combine both.

Merge Strategy

When resolving merge conflicts, always understand the intent of both changes before choosing a resolution. Taking "theirs" or "yours" blindly can silently discard important changes. Read the surrounding context, check the related commit messages, and test the merged result.

Power Tips for Text Comparison

  1. Ignore whitespace when it does not matter. Use diff -w or git diff -w to skip whitespace-only changes. This is invaluable after reformatting code -- you only see the real logic changes.
  2. Use --word-diff for prose. Standard git diff highlights entire lines. git diff --word-diff shows exactly which words changed, which is much easier to review for documentation and content.
  3. Compare clipboard content directly. On macOS: diff <(pbpaste) file.txt compares your clipboard against a file. On Linux: diff <(xclip -o) file.txt. Or just paste both into the QTool Diff Checker.
  4. Hash before diffing large files. If you just need to know whether two large files are identical (without seeing the differences), compare their checksums first: sha256sum file1 file2. If the hashes match, the files are identical. The Hash Generator can do this in the browser.
  5. Diff structured data with the right tool. Comparing Markdown? Use the Markdown Editor with preview to see rendered differences. Comparing word counts across versions? Use the Word Counter on each version.
  6. Save diffs for documentation. git diff > changes.patch creates a patch file that documents exactly what changed. This is useful for code reviews, change logs, and audit trails.

Frequently Asked Questions

How do I compare two text files online for free?

To compare two text files online, use a browser-based diff tool like the QTool Diff Checker. Paste the original text on the left side and the modified text on the right side, then click Compare. The tool highlights additions in green, deletions in red, and modifications in yellow. No signup or software installation is needed. The comparison runs entirely in your browser, so your text is never sent to a server. This makes browser-based diff tools safe for comparing sensitive content like configuration files and code.

What is the difference between line-based and word-based diff?

Line-based diff compares text one line at a time. If any character on a line changes, the entire line is marked as modified. This is the default mode used by git diff and the Unix diff command. Word-based diff compares text at the word level. If one word on a line changes, only that word is highlighted -- not the entire line. This makes word-based diff more useful for comparing prose, documentation, and content where changes are scattered within lines. Character-based diff goes even further, highlighting individual character changes. Choose line-based for code, word-based for text content, and character-based when you need to spot exact character-level differences like encoding issues.

How do I read unified diff output?

Unified diff output (the format used by git diff) uses three markers: lines starting with + (plus) are additions that exist only in the new version. Lines starting with - (minus) are deletions that exist only in the old version. Lines with no prefix are unchanged context lines. The @@ header shows the line numbers: @@ -1,5 +1,6 @@ means the chunk starts at line 1 in the old file (5 lines shown) and line 1 in the new file (6 lines shown). A modified line appears as a deletion of the old version followed by an addition of the new version.

Can I compare JSON files with a diff tool?

Yes, you can compare JSON files with a text diff tool, but for best results, format both JSON files first so the structure is consistent. Unformatted JSON often appears as a single long line, which makes line-based diff useless. Use a JSON formatter to pretty-print both files with consistent indentation, then compare them. Some diff tools have dedicated JSON comparison modes that understand the JSON structure and can ignore key ordering differences. QTool offers both a JSON Formatter (to normalize the structure) and a Diff Checker (to compare the results) as free tools.

What is the best diff tool for code reviews?

For code reviews, the best diff tools depend on your workflow. GitHub, GitLab, and Bitbucket have built-in diff viewers that show side-by-side comparisons with syntax highlighting. For local code review, VS Code's built-in diff editor (right-click a file, Select for Compare, then Compare with Selected) is excellent. For standalone tools, Meld (Linux/Windows), Kaleidoscope (macOS), and Beyond Compare (cross-platform) offer advanced features like three-way merge and folder comparison. For quick one-off comparisons without installing anything, browser-based tools like the QTool Diff Checker are the fastest option.

How do I compare files from the command line?

On macOS and Linux, use the diff command: diff file1.txt file2.txt for basic comparison, or diff -u file1.txt file2.txt for unified format (the most readable). Use diff --color for colored output (GNU diff). For comparing directories, use diff -r dir1/ dir2/. On any system with Git installed, git diff --no-index file1.txt file2.txt provides colored, paginated output with word-level highlighting. For very large files, colordiff (a wrapper around diff) and delta (a modern diff viewer) provide better readability. On Windows, fc (File Compare) is the built-in equivalent: fc file1.txt file2.txt.

Explore QTool for free

Browse 269 indexed tool pages with no QTool account required, and inspect the source on GitHub.

View on IT-Tools →
NT

Christian Bucher

We build free, privacy-first developer tools. 269 tools for text processing, comparison, formatting, and more -- all browser-based, no signup required.

Related Tools

CSS Box Shadow Generator · Free Text Diff Viewer · Free Code Diff Viewer

Related Tools

Free Git Diff Viewer · Emoji Picker & Search · Free API Mock Server

Built by Miguel

Need a custom tool or website?

From . Delivered in 24-48h. You own the code.

View Services →