Unified diff generator
Compare two texts line by line and produce a diff in the format of diff -u and git diff.
A clear answer. Here’s how.
Finds a shortest edit script between the two lists of lines with Myers’s O(ND) algorithm, so the diff is as small as it can be, then groups the changes into hunks with the chosen amount of context and writes them as @@ -start,count +start,count @@ headers followed by lines marked space (unchanged), - (removed) and + (added), exactly as diff -u does. Hunks closer than twice the context are merged. A last line with no newline is marked “\ No newline at end of file” and counts as different from the same line with one. Ignore options change what is compared, not what is printed. Up to 50,000 lines each and 2,000 edits.
How this is checked
4 reference checks passed These 4 cases were run when this page was built, on 20 October 2026, and all reproduce within the stated tolerance. The same cases are part of the automated tests that run on every change to Toolmoz. Engine version 1.
See the checks and where each expected answer comes from
Case 1
- Inputs
- Original text alpha beta gamma delta Changed text alpha BETA gamma delta epsilon
- Expected, and what Toolmoz gave
- text expected --- a/original.txt +++ b/modified.txt @@ -1,4 +1,5 @@ alpha -beta +BETA gamma delta +epsilon , Toolmoz --- a/original.txt +++ b/modified.txt @@ -1,4 +1,5 @@ alpha -beta +BETA gamma delta +epsilon Lines added expected 2, Toolmoz 2Lines removed expected 1, Toolmoz 1Lines unchanged expected 3, Toolmoz 3Hunks expected 1, Toolmoz 1
- Where the expected answer comes from
- Output of GNU diff -u on the same two files, with the header names replaced
- Allowed difference
- exact
Case 2
- Inputs
- Original text one twoChanged text one two three
- Expected, and what Toolmoz gave
- text expected --- a/original.txt +++ b/modified.txt @@ -1,2 +1,3 @@ one -two \ No newline at end of file +two +three , Toolmoz --- a/original.txt +++ b/modified.txt @@ -1,2 +1,3 @@ one -two \ No newline at end of file +two +three Lines added expected 2, Toolmoz 2Lines removed expected 1, Toolmoz 1
- Where the expected answer comes from
- Output of GNU diff -u: the old last line had no newline, so it is replaced by the same line with one
- Allowed difference
- exact
Case 3
- Inputs
- Original text 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Changed text 1 two 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 eighteen 19 20
- Expected, and what Toolmoz gave
- text expected --- a/original.txt +++ b/modified.txt @@ -1,5 +1,5 @@ 1 -2 +two 3 4 5 @@ -15,6 +15,6 @@ 15 16 17 -18 +eighteen 19 20 , Toolmoz --- a/original.txt +++ b/modified.txt @@ -1,5 +1,5 @@ 1 -2 +two 3 4 5 @@ -15,6 +15,6 @@ 15 16 17 -18 +eighteen 19 20 Hunks expected 2, Toolmoz 2Lines added expected 2, Toolmoz 2Lines removed expected 2, Toolmoz 2
- Where the expected answer comes from
- Output of GNU diff -u on the numbers 1 to 20 with lines 2 and 18 changed: two hunks of three lines of context each
- Allowed difference
- exact
Case 4
- Inputs
- Original text same text Changed text same text
- Expected, and what Toolmoz gave
- text expected (No differences) , Toolmoz (No differences) Lines added expected 0, Toolmoz 0Lines removed expected 0, Toolmoz 0Hunks expected 0, Toolmoz 0
- Where the expected answer comes from
- Identical texts have no hunks
- Allowed difference
- exact
What this shows: the engine reproduces independently worked values for these cases. It does not prove every possible input is right. To test an answer you were given, see how to check a number; to see what is and is not checked across Toolmoz, see the accuracy ledger.
See a worked example
Worked example
A fixed demonstration, separate from the values you enter above.
- Original text
alpha beta gamma delta
- Changed text
alpha BETA gamma delta epsilon
- Name for the original in the header
- a/original.txt
- Name for the changed text in the header
- b/modified.txt
- Lines of context around each change
- 3
- White space
- Compare exactly
- Letter case
- Case matters
Example result
- Lines added
- 2
- Lines removed
- 1
- Lines unchanged
- 3
- Hunks
- 1
- Original lines
- 4
- Changed lines
- 5
- Similarity (unchanged lines ÷ average length)
- 66.7%
A minimal line-by-line diff (Myers, 1986) in the format of diff -u and git diff, with 3 lines of context. Lines are compared whole; a final line without a newline counts as different from the same line with one. Apply the result with patch -p1 or git apply after fixing the file names if needed.