Menu

Search toolsChangelog

to move to openDescribe the problem, not the tool

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.

The left side of the comparison. CRLF and CR newlines are normalised to LF before lines are compared.

The right side. A changed line is represented as one deletion and one addition, as unified diff requires.

Unchanged lines shown around each edit. Nearby edits merge when their context overlaps.

Change summary
2 lines added, 2 lines removed
Lines added
2
Lines removed
2
Lines unchanged
2
Change hunks
2

Unified diff patch

app.conf.patch · 111 B

A standard --- / +++ patch with @@ ranges, selected context and explicit missing-final-newline markers.

The complete line edit script

Removed1host=localhost
Added1host=127.0.0.1
Unchanged22port=3000
Unchanged33mode=development
Removed4cache=false
Added4cache=true
What to take away
  1. Zero context does not change which lines are additions or deletions; it changes only how much unchanged material surrounds them.

  2. Distant edits remain separate hunks instead of being joined by lines that are not needed to describe either change.

  3. 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

  1. Normalise CRLF and lone CR line endings to LF, while recording whether each document's final logical line has a terminating newline.
  2. Build a longest-common-subsequence matrix over complete line text plus its termination state, choosing deletion before insertion when several minimum scripts tie.
  3. Expand every changed edit by the requested number of unchanged context lines and merge ranges that touch or overlap into unified diff hunks.
  4. 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.