DevBolt
Processed in your browser. Your data never leaves your device.

Unified Diff Format Explained

The unified diff format is the standard output of git diff and is used by patch tools worldwide. Paste any unified diff into the viewer above to see it rendered with syntax highlighting.

← Back to tools

Git Diff Viewer

Paste unified diff output (from git diff) and view it with syntax highlighting, line numbers, and side-by-side or inline display.

Ctrl+Enter to parse
Samples:

Paste a unified diff above to render it with syntax highlighting and line numbers.

What is unified diff format?

Unified diff format (also called unidiff) shows changes between two files in a compact, human-readable way. It was introduced by GNU diff and is now the default output format for git diff. Each diff starts with file headers (--- and +++ lines), followed by one or more hunks that show the actual changes with surrounding context lines.

Anatomy of a unified diff

A unified diff has several parts: (1) The diff header line starting with 'diff --git a/file b/file'. (2) File metadata lines like 'index abc1234..def5678'. (3) The old file name prefixed with '--- a/'. (4) The new file name prefixed with '+++ b/'. (5) Hunk headers like '@@ -10,7 +10,8 @@' indicating line ranges. (6) Context lines starting with a space. (7) Removed lines starting with '-'. (8) Added lines starting with '+'.

Understanding hunk headers

The hunk header @@ -10,7 +10,8 @@ means: in the old file, this hunk starts at line 10 and spans 7 lines; in the new file, it starts at line 10 and spans 8 lines. The numbers after the comma indicate the number of lines shown (context + changes). Some hunks include a function name after the closing @@ for additional context.

Frequently Asked Questions

What do the + and - symbols mean in a diff?

Lines starting with '-' (minus) were removed from the old version. Lines starting with '+' (plus) were added in the new version. Lines starting with a space are unchanged context lines shown for reference. Lines starting with '@@' are hunk headers indicating line positions.

What is the difference between unified and context diff format?

Unified diff (git diff default) shows changes inline with +/- prefixes and is more compact. Context diff (diff -c) shows old and new versions in separate blocks marked with *** and ---. Unified format is preferred for code review and version control because it is more readable and produces smaller patches.

Related Inspect Tools