How do I compare two text files for differences online?

Dark navy cover card with the title 'How do I compare two text files for differences online?' in white and a green accent bar

To compare two text files online, open a browser diff tool, paste the original into one box and the changed version into the other, and read the highlighted lines. For confidential, large or whitespace-heavy files, compare the two text files on your own machine with diff, fc, git diff --no-index or VS Code instead.

How to compare two text files in a browser

A browser diff tool is the quickest route when the files are small and not secret. The steps barely change from site to site:

  1. Open the first file in a text editor and copy all of it.
  2. Paste it into the left box (often labelled "original").
  3. Paste the second file into the right box ("changed").
  4. Run the comparison and scan the marked lines.
  5. Turn on ignore options (whitespace, case) if the result is full of noise.

Most tools show deletions on the left and additions on the right, usually in red and green. A side-by-side view puts the two versions in columns. An inline view stacks removed and added lines in one column, which reads better on a narrow screen.

Some sites take uploads instead of pasted text. Convenient, but the file usually leaves your computer.

Why one inserted line can make everything look different

Diff tools differ most in how they line up the two files, and that decides whether the result is useful. A simple tool compares line 1 with line 1, line 2 with line 2, and so on. A real diff program first finds the lines both files share, then reports only what was added or removed around them.

File A:

host=db.local
retries=3
user=app
timeout=5

File B adds one line at the top:

# staging config
host=db.local
retries=3
user=app
timeout=5

A position-by-position comparison pairs # staging config with host=db.local, host=db.local with retries=3, and so on. Every pair differs, so all five lines get flagged. An aligning diff reports one added line.

GNU diff uses the alignment approach. Its manual says the basic algorithm comes from Eugene W. Myers' paper "An O(ND) Difference Algorithm and its Variations" (Algorithmica, 1986), per the GNU Diffutils manual. The manual also admits diff "takes shortcuts to run faster", though its output is usually close to the shortest possible. The --minimal (-d) option trades speed for a smaller result.

Git goes further. git diff lets you pick the algorithm with --diff-algorithm (patience, minimal, histogram or myers, with myers as the default), per the git-diff manual page.

Ignore whitespace, case and line endings

Most "phantom" differences come from spaces, tabs, letter case or Windows line endings. If a diff shows dozens of changes, switch these off and run it again.

GNU diff has a separate flag for each kind of noise:

What you want to ignore GNU diff option What it does
Trailing spaces -Z / --ignore-trailing-space Ignores white space at line end
Amount of spacing -b / --ignore-space-change Treats runs of white space as equal
All spacing -w / --ignore-all-space Ignores white space even where one line has none
Blank lines -B / --ignore-blank-lines Ignores inserted or deleted blank lines
Letter case -i / --ignore-case Treats upper and lower case as the same
Windows line endings --strip-trailing-cr Treats CRLF line ends as plain newlines

One catch: -w does not ignore newline changes. Diff is line-oriented, so a newline always ends a line. A paragraph rewrapped onto two lines still shows up.

For code and JSON, run both files through the same formatter first to strip indentation noise. See our guide to comparing JSON files and ignoring key order.

Compare two files with built-in commands

Your operating system already has a file comparison command, and it never uploads anything. Reach for it when the files are private or too big to paste.

Linux and macOS: diff. diff -u old.txt new.txt prints a unified diff with 3 lines of context around each change. diff -y old.txt new.txt gives a side-by-side layout, normally 130 columns wide. diff -q only tells you whether the files differ, according to the GNU Diffutils manual.

Windows: fc. fc old.txt new.txt compares two files and lists the differences. The /l mode compares line by line and tries to resynchronize after a mismatch; /c ignores case, /w compresses spaces and tabs, and /n adds line numbers, per Microsoft's fc documentation. In PowerShell, type fc.exe, because fc alone is an alias for Format-Custom.

On big files, watch the buffer. The same page says fc's line buffer defaults to 100 lines, and fc cancels the comparison when the files have more than 100 consecutive differing lines. Raise it with /lb if that happens.

Any system with Git: git diff --no-index. git diff --no-index old.txt new.txt compares two paths on disk, even outside a repository. You get Git's coloured output plus extras such as --word-diff, which highlights changed words inside each line, and --color-moved, which colours moved lines differently, per the git-diff manual page.

Compare two text files in VS Code

VS Code has a built-in diff editor with side-by-side panes and inline change markers. From a terminal, run code --diff old.txt new.txt (or code -d), which opens a file difference editor and needs two file paths, per the VS Code command-line docs.

This is my default for code and config files: syntax colours, editable panes, and nothing leaves the machine. For the cleanup step before a diff, see formatting JSON in VS Code.

Which method should you pick?

Pick based on what is in the files and how big they are. Speed barely matters, since every option here takes seconds.

Situation Best option
Short, non-sensitive snippets Browser diff tool
API keys, customer data, contracts diff, fc or VS Code on your machine
Large logs or exports diff or git diff --no-index
Whitespace or tab noise diff -w, fc /w, or a tool's ignore option
Small wording changes in long lines git diff --word-diff
Code you want to read with highlighting VS Code code --diff

My take: use a browser tool for throwaway text and a local command for anything you'd hesitate to email. Pasting a production config into an unknown website is no different from mailing it to a stranger. More on that in is an online JSON formatter safe.

A limitation of our own diff checker

Our diff checker runs entirely in the page, so pasted text is not sent anywhere by the tool code. But it is a line-by-line checker: it compares line N in the first box with line N in the second and does not realign inserted or deleted lines.

Feed it the example above, with one line added at the top, and every line shows as changed. Use it only where lines stay put, such as two versions of the same .env file or a list where values changed but nothing moved. If lines were added or removed in the middle, use diff, git diff --no-index or VS Code.

FAQ

How do I compare two text files without installing anything?

Paste the original text into the left box of a browser diff tool and the changed text into the right box. Removed lines are marked on one side and added lines on the other. Check that the tool processes text in the page if the files are private.

Why does a diff show every line as changed after one insertion?

Some tools compare line 1 with line 1, line 2 with line 2 and so on. One inserted line shifts everything after it, so every later pair looks different. Tools that align matching lines first, like GNU diff, show only the inserted line.

How do I ignore whitespace when comparing two files?

With GNU diff, use -b to ignore changes in the amount of white space, or -w to ignore all white space. On Windows, fc /w compresses runs of tabs and spaces. Many web diff tools have an ignore-whitespace checkbox.

Can I compare two files on Windows without extra software?

Yes. Run fc file1.txt file2.txt in Command Prompt. In PowerShell, type fc.exe, because fc on its own is an alias for Format-Custom.

Is it safe to paste confidential text into an online diff checker?

Only if the tool compares the text in your browser and does not upload it. If you can't confirm that, compare the files locally with diff, fc, git diff or your code editor.

Sources