b2KIT

Diff / Patch Viewer

Visualize unified diffs and patch files with color-coded additions and deletions.

How to Use Diff / Patch Viewer

  1. 1

    Paste the diff

    Enter a unified diff or patch file content.

  2. 2

    Review the changes

    See additions in green and deletions in red with line numbers.

  3. 3

    Navigate hunks

    Click through individual change hunks to review each section.

Tested tool guide Tested browser tools Checked August 16, 2026

What Diff / Patch Viewer does, with a checked example

Diff / Patch Viewer converts unified diff text into a structured, color-coded view of each affected file and hunk. It distinguishes removed lines, added lines, and unchanged context while retaining the old and new line positions declared by each hunk header. The frequent mistake is pasting two ordinary source files and expecting a comparison. This viewer expects an existing unified diff or patch, including its line prefixes and hunk metadata.

Worked example

A concrete input and expected output from the current implementation.

Input

--- a/greeting.txt
+++ b/greeting.txt
@@ -1 +1 @@
-Hello, world.
+Hello, Codex.

Expected output

One file comparison with old path `a/greeting.txt` and new path `b/greeting.txt`. The single hunk marks `Hello, world.` as a deletion at old line 1 and `Hello, Codex.` as an addition at new line 1.

The hunk header declares one old line and one new line, both beginning at line 1. The minus-prefixed line is removed, and the plus-prefixed line replaces it.

How the result is produced

1

Reading file and hunk headers

The `---` and `+++` headers identify the old and new file paths. A header such as `@@ -12,3 +12,4 @@` says that the displayed hunk covers three lines beginning at old line 12 and four lines beginning at new line 12. Those ranges provide line positions; they are not lines of source code.

2

Classifying hunk lines

Within a hunk, a line beginning with `-` is a deletion, a line beginning with `+` is an addition, and a line beginning with one space is unchanged context. The file header `+++` is not an added source line because it occurs in the patch header. A `\ No newline at end of file` marker describes file termination rather than content.

Good uses

  • Review a patch copied from an issue, email, build log, or command-line diff.
  • Check exactly which lines a generated patch proposes to insert and remove before applying it.
  • Inspect a multi-file unified diff when raw plus and minus prefixes are difficult to follow.

Limits and checks

  • The view represents the patch text supplied; it does not prove that the patch matches the intended source files.
  • Unchanged lines outside each hunk are omitted, so the rendered patch is not a complete view of the resulting file.
  • Hunk ranges and line prefixes are structural. Missing prefixes or incorrectly copied headers can make otherwise familiar code an invalid unified diff.

Common questions

Does this tool generate a diff from two source files?

No. Its input is already formatted unified diff or patch text. To compare two raw file versions, first produce a unified diff with a comparison tool, then paste that result here. The viewer is for interpreting the patch structure and changes, not for inferring changes from separate before and after documents.

Does every line in the final file appear as an addition?

No. Added lines are only the plus-prefixed lines introduced by the patch. The resulting file also retains context lines shown with a leading space and unchanged lines omitted from the patch entirely. Deleted lines do not remain in the new version, although the viewer displays them so the change can be reviewed.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools