Compare Config Texts With No Context Lines
Set context lines to zero before downloading the diff. If one value changes near the beginning and another changes near the end, the output contains two small @@ hunks with only removed and added lines; unchanged configuration stays out of the patch but still participates in finding the minimum edit script.
Unified diff patch
A standard --- / +++ patch with @@ ranges, selected context and explicit missing-final-newline markers.
The complete line edit script
| Removed | 1 | host=localhost | |
| Added | 1 | host=127.0.0.1 | |
| Unchanged | 2 | 2 | port=3000 |
| Unchanged | 3 | 3 | mode=development |
| Removed | 4 | cache=false | |
| Added | 4 | cache=true |
Zero context does not change which lines are additions or deletions; it changes only how much unchanged material surrounds them.
Distant edits remain separate hunks instead of being joined by lines that are not needed to describe either change.
The on-page edit table still lists the complete script, while the patch artifact obeys the selected compact context.
How it works
How it is done
- Normalise CRLF and lone CR line endings to LF, while recording whether each document's final logical line has a terminating newline.
- Build a longest-common-subsequence matrix over complete line text plus its termination state, choosing deletion before insertion when several minimum scripts tie.
- Expand every changed edit by the requested number of unchanged context lines and merge ranges that touch or overlap into unified diff hunks.
- Write cleaned --- and +++ labels, exact @@ start,count ranges and space, minus or plus line prefixes into a downloadable patch.
What it assumes
- Comparison is line-based and exact after newline normalisation; whitespace, case and Unicode-normalisation differences are not ignored.
- Each side is limited to 2,000 characters, keeping the quadratic longest-common-subsequence matrix bounded in the browser.
- More than one minimum edit script can exist. Deletion-first ties make this output repeatable but not uniquely mathematically privileged.
- A syntactically formed patch can still fail against a third file whose surrounding content has changed; this tool does not apply or merge patches.
Common questions
Is a zero-context unified diff still a valid patch?
Yes. Its range headers can carry zero-length old or new ranges, and every changed line still has the required plus or minus prefix.
When should I keep context lines instead?
Keep context when a person must review the surrounding meaning or when a patch will be applied to a file that may have shifted since the comparison.
Sources
The full method, worked example and every assumption behind this figure are on Text Diff Maker.