Diff Tool for Developers — How to Compare Files & Strings
Diff tools are fundamental to software development — code review, debugging, config management, and version control all depend on seeing exactly what changed. This guide covers how to read unified diff output, git diff, command-line tools, and when to use an online diff checker.
What a Diff Shows
A diff compares an original (left/before) and a modified (right/after) version of text. The output shows:
- + lines — added in the new version
- - lines — removed from the original
- Context lines — unchanged lines surrounding each change (usually 3)
Reading a Unified Diff
Here is a real unified diff output and what each part means:
| Symbol | Meaning |
|---|---|
| --- | Original file (a/ = before) |
| +++ | Modified file (b/ = after) |
| @@ -4,7 +4,8 @@ | Hunk: original starts at line 4 (7 lines); modified starts at line 4 (8 lines) |
| - | Line removed from original |
| + | Line added in modified |
| (space) | Context line — unchanged in both versions |
git diff Explained
git diff is the most common way developers see diffs. The output is unified diff format with color coding.
Using diff on the Command Line
Code Review Diffs vs File Diffs
Code review tools (GitHub, GitLab, Bitbucket) show a richer diff experience than plain unified diff:
| Feature | Plain diff/git diff | Code review UI |
|---|---|---|
| Inline comments | No | Yes |
| Syntax highlighting | No (terminal colors only) | Yes |
| Side-by-side view | With -y flag | Built-in toggle |
| Character-level diff | With --word-diff | Built-in highlighting |
| Viewing full file context | Requires manual scroll | Expandable context |
| Reviewing multiple files | Pipe through less | Single-page navigation |
When to Use an Online Diff Tool
Command-line diff and git diff are ideal for files in version control. Use an online diff tool when:
- Comparing clipboard content — API responses, log excerpts, copied text
- Comparing config file versions that aren't in git
- Sharing a diff with a teammate who doesn't need full git context
- Comparing JSON responses between two environments or API calls
- Quick before/after comparison of a generated or transformed string
DevKit's Diff Checker processes everything client-side — your content never leaves your browser.
Related Tools
Related Guides
FAQ
What does a diff tool do?
A diff tool compares two pieces of text (files, strings, or code) and shows what changed between them. Lines added are shown in green (prefixed with +), lines removed are shown in red (prefixed with -), and unchanged context lines are shown without a prefix.
What is a unified diff?
Unified diff is the standard output format produced by the Unix diff command and git diff. It shows added lines (+), removed lines (-), and 3 lines of unchanged context around each change. The @@ markers show the line numbers of each change hunk.
What is the difference between git diff and git diff --staged?
git diff shows changes in the working tree that haven't been staged yet. git diff --staged (or git diff --cached) shows changes that have been staged but not yet committed. git diff HEAD shows all changes since the last commit, both staged and unstaged.
How do I compare two files on the command line?
Use: diff file1.txt file2.txt for the standard unified format. Use diff -u file1.txt file2.txt for explicit unified format with context lines. Use diff -y file1.txt file2.txt for side-by-side comparison.
When should I use an online diff tool instead of git diff?
Online diff tools are useful when you don't have files checked into git (e.g., comparing JSON API responses, config file versions, clipboard snippets), when you want to share a diff with someone without them needing git, or when you want a cleaner visual comparison than terminal output.