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.
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.
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.
// Unified diff format anatomy
--- a/src/app.ts // original file
+++ b/src/app.ts // modified file
@@ -10,7 +10,8 @@ // hunk header: line numbers
// context line (unchanged) // starts with space
-const port = 3000; // removed line (starts with -)
+const port = parseInt( // added line (starts with +)
+ process.env.PORT || "3000" // added line
+);
// more context // unchanged
// Hunk header: @@ -oldStart,oldCount +newStart,newCount @@
// -10,7 means: starting at line 10, showing 7 lines from original
// +10,8 means: starting at line 10, showing 8 lines in modifiedAnatomy 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
GitHub Actions Validator
Validate GitHub Actions workflow YAML files for syntax, triggers, job structure, step config, needs dependencies, and deprecated actions
Aspect Ratio Calculator
Calculate aspect ratios from any dimensions, resize while preserving proportions, and find equivalent sizes. Device presets for phones, tablets, monitors, and social media
XPath Tester
Test XPath expressions against XML data with real-time evaluation — select elements, filter by attributes, navigate axes, and use XPath functions
SQL Playground
Run SQL queries in your browser with a full SQLite database powered by WebAssembly — practice JOINs, CTEs, window functions, aggregations, and more