A diff is a data comparison algorithm and output format displaying line-by-line insertions, deletions, and modifications between text files.
A Diff is a data comparison utility and standardized output format that calculates and displays the discrete line-by-line and character-by-character differences between two files or text streams. Originally created in 1974 for Unix by Douglas McIlroy, diff algorithms solve the Longest Common Subsequence (LCS) problem. Today, diff calculations power version control systems like Git, code review platforms (GitHub pull requests), automated patch utilities (patch), and live visual comparison tools.
Compare text snippets side-by-side or in unified view using our interactive Diff Viewer or resolve merge collisions with the Git Conflict Resolver.
| Specification | Details |
|---|---|
| Pioneering Creator & Year | Douglas McIlroy (Unix, 1974) |
| Standard Output Formats | Unified Diff (-u), Context Diff (-c), Normal Diff |
| Dominant Algorithm | Eugene Myers' $O(ND)$ Difference Algorithm (1986) |
| Patch Application Utility | POSIX patch command (Applies diff outputs directly to source files) |
| Primary Ecosystems | Git (git diff), Mercurial, SVN, Linux kernel mailing lists |
The Unified Diff format is the universal standard for code review interfaces. It consolidates changes into a single contiguous view with header lines, range coordinates (hunks), and contextual surrounding lines:
--- original.js 2026-09-01 10:00:00.000000000 +0000
+++ updated.js 2026-09-04 12:00:00.000000000 +0000
@@ -1,6 +1,6 @@
function calculateTotal(items) {
- let total = 0;
+ let subtotal = 0;
for (const item of items) {
- total += item.price;
+ subtotal += item.price * (1 - item.discount);
}
- return total;
+ return subtotal;
}
@@ -1,6 +1,6 @@-1,6: In the original file (-), this hunk starts at line 1 and spans 6 lines.+1,6: In the modified file (+), this hunk starts at line 1 and spans 6 lines.- (Minus prefix): Indicates an original line that was removed or replaced.+ (Plus prefix): Indicates a newly inserted line.Most version control systems (including Git's default engine) rely on the Myers Difference Algorithm:
-).+).import * as diff from 'diff';
const oldText = 'const name = "DevFlow";\nconst port = 8080;\n';
const newText = 'const name = "DevFlow Tools";\nconst port = 3000;\n';
// Generate standard Unified Diff patch
const patch = diff.createPatch(
'config.ts', // filename
oldText, // old string
newText, // new string
'v1.0.0', // old header
'v1.1.0' // new header
);
console.log(patch);
A unified diff presents additions and deletions inline within a single column of code, making it compact and easy to read on narrower screens. A side-by-side (split) diff displays the original file on the left and modified file on the right, which makes comparing wide refactoring changes easier to track visually.
A two-way diff compares File A directly against File B. A three-way diff compares two branch heads against their common base ancestor (BASE). When both branches edit the exact same lines differently since the base commit, Git cannot resolve the change automatically and flags a merge conflict.
Yes. You can paste any two text or code files into our browser-based Diff Viewer to view syntax-highlighted side-by-side or inline comparisons without uploading files to a server.
Free, browser-based utilities to test, generate, and inspect Diff & Unified Diff Format payloads directly.