How does a text diff work?
A diff finds the smallest set of insertions and deletions that turns one text into another, usually line by line, and reports them in a form a reader or a tool can apply: the unified format marks removed lines with "-" and added lines with "+" under a header giving the line numbers. Whitespace and line-ending differences (CRLF vs LF, trailing spaces) are real differences to a diff unless it is told to ignore them, which is why comparing expected and actual output often needs normalisation first.
@@ header gives where a hunk starts and how many lines it spans in each file; below it, a space marks context, - a removed line and + an added line.Unified patch
Part 1:--- a/original.txt Part 2:+++ b/modified.txt @@ Part 3:-2,4 Part 4:+2,5 @@ Part 5: host: api.mutqan.sa Part 6:- port: 8080 Part 7:+ port: 8443 Part 5: timeout: 30s Part 7:+ tls: true Part 5: features:
- 1Original fileBefore
git apply, put your file’s path here in place oforiginal.txt, keepinga/ - 2Modified fileThe same path, keeping
b/ - 3Original: from line 2, 4 linesCounts the context and removed lines
- 4Modified: from line 2, 5 linesCounts the context and added lines
- 5Context line (space)Unchanged; “Patch context lines” sets how many surround each change
- 6Removed line (
-)Only in the original - 7Added line (
+)Only in the modified text
The start of the tool’s “Unified patch” for its sample (Load example), with “Patch context lines” set to 1; the default is 3.
How to use Text Diff
- Paste the original text on the left and the modified text on the right.
- Choose Lines or Words and any ignore options.
- Click Compare to see the unified view, side-by-side table and patch.
- Download the .patch file, replace original.txt and modified.txt in its --- and +++ lines with the path of your file, and apply it with git apply or patch -p1.
Text Diff features
- Line mode with unified view, side-by-side table and a downloadable unified patch
- Word mode with inline insert/delete highlighting for prose
- Ignore whitespace and ignore case options
- Similarity percentage and added / removed / unchanged counts
- Handles large files quickly with anchor-based splitting for heavily changed inputs
- Configurable patch context lines
Text Diff example
Compare two configuration files
Input:
Left: port: 8080
logging: info
Right: port: 8443
tls: true
logging: warnOutput:
- port: 8080
- logging: info
+ port: 8443
+ tls: true
+ logging: warn
Similarity 0%Frequently asked questions about Text Diff
Which algorithm is used?
The Myers O(ND) shortest-edit-script algorithm — the same family used by git. Very large or very different inputs are split at unique anchor lines so results stay fast and readable.
Can I get a patch file?
Yes. The "Unified patch" output is in the standard unified diff format (--- / +++ / @@ hunks). Its header lines name the files a/original.txt and b/modified.txt, and git apply takes the path from them, so replace both names with the path of your file (keeping the a/ and b/ prefixes) before running git apply or patch -p1.
What does "Ignore whitespace" do?
Lines that differ only in spaces, tabs or indentation are treated as equal. Combine it with "Ignore case" for a case-insensitive comparison.
How does word mode differ from line mode?
Word mode aligns individual words and punctuation and shows insertions and deletions inline, which is ideal for prose and translations. Line mode is better for code and configuration files.
Is there a size limit?
Each text may be up to 2 MB. Word mode is limited to 400,000 characters in total because it works on a much finer granularity.
Technical notes
Lines are diffed with the Myers algorithm after stripping a common prefix and suffix. When the edit distance exceeds a budget, the engine finds lines that are unique on both sides, computes the longest increasing subsequence of their positions and recurses between those anchors — the same idea as patience diff — which keeps results readable for very different documents.
References
- diff — POSIX.1-2017 (IEEE Std 1003.1-2017)The standard definition of a line-by-line comparison and of the unified and context output formats.