TextyConverterbeta
⌘K

Text Diff (Unified)

Compare two texts and produce a unified diff — the same format git diff and patch use.

About Text Diff (Unified)

Unified diff is the standard text format for representing changes between two files. Removed lines are prefixed with '-', added lines with '+', and context lines with a space. Hunks are separated by @@ markers showing line numbers. This is the format produced by git diff and consumed by patch, so the output is easy to apply or share.

When to use it

  • Producing a patch to share with a teammate
  • Generating diff output for inclusion in a code review
  • Saving a comparison result as a .patch file
  • Inspecting changes in a format that's familiar to anyone who uses git

How it works

The createTwoFilesPatch function from jsdiff produces a standard unified-diff string with @@ hunk headers, ± line prefixes, and context lines. The number of context lines defaults to 3 (matching git's default).

Examples

Two versions of a config file
@@ -3,5 +3,5 @@
   timeout: 30
-  retries: 3
+  retries: 5
   verbose: true

Frequently asked questions

Can I apply this output as a patch?
Yes. Save the output to a .patch file and run `patch -p1 < file.patch`, or feed it to `git apply`. The format follows the standard unified-diff specification.
How are file headers handled?
The output includes 'original' and 'modified' labels in the file header. To use real filenames in a real patch, edit the first two lines after copying.
What about line endings?
Both LF and CRLF are accepted; the diff is computed on logical lines so line ending differences don't pollute the output.

Related tools