What is Diff? Complete Guide with Examples

3 min readdeveloper

Last updated: Invalid Date

Diff is a tool and output format that shows the differences between two files or text versions. Originally a Unix command-line utility, diff is now fundamental to version control systems (Git), code review platforms (GitHub, GitLab), and development workflows. The diff output shows which lines were added, removed, or modified between two versions, using a standardized format that both humans and tools can interpret.

Try It Yourself

Use our free tools to experiment with diff (code comparison).

How Does Diff (Code Comparison) Work?

Diff algorithms compute the minimum edit distance between two sequences of lines using dynamic programming approaches like the Myers algorithm. The result is an edit script describing the minimal set of insertions and deletions to transform one file into the other. Output formats include unified diff (showing context with +/- prefixes), side-by-side (two columns), and context diff (showing surrounding lines). Git extends basic diff with word-level highlighting, rename detection, and binary file handling.

Key Features

  • Unified diff format showing changes with + (added) and - (removed) prefixes and context lines
  • Side-by-side comparison mode for visual review of changes
  • Word-level and character-level diff for identifying specific changes within lines
  • Git integration for comparing commits, branches, staging area, and working tree changes
  • Directory comparison (recursive diff) for finding differences across entire projects

Common Use Cases

Git Version Control

Every git commit stores diffs — the changes from the previous version. Commands like git diff, git log -p, and git show display diffs for reviewing changes, understanding history, and debugging regressions.

Pull Request Code Review

GitHub and GitLab present pull request changes as diffs, allowing reviewers to see exactly what code was added, removed, or modified in each file, with inline commenting for feedback.

Configuration Change Tracking

Operations teams compare configuration files between environments or versions to identify what changed, verify deployments, and troubleshoot issues caused by config modifications.

Why Diff (Code Comparison) Matters

Understanding diff (code comparison) is essential for anyone working in software development. It is not just a theoretical concept — it directly impacts the quality, efficiency, and reliability of your work. Professionals who understand the underlying principles make better decisions about which tools and approaches to use.

Whether you are a beginner learning the fundamentals or an experienced professional looking for a quick refresher, grasping how diff (code comparison) works helps you debug issues faster, communicate more effectively with your team, and choose the right tool for each specific task.

Getting Started with Diff (Code Comparison)

The fastest way to learn diff (code comparison) is to experiment with it hands-on. Use our free tools linked above to try different inputs and see how the output changes. Start with simple examples, then gradually increase complexity as you build intuition for how diff (code comparison) behaves.

For deeper learning, explore the related guides linked at the bottom of this page — they cover adjacent concepts that will strengthen your understanding of the broader ecosystem. Each guide includes practical examples and links to tools you can use immediately.

Frequently Asked Questions

What do the + and - symbols mean in a diff?
Lines starting with + are additions (new content). Lines starting with - are deletions (removed content). Lines without a prefix are unchanged context lines shown for reference. Modified lines appear as a deletion of the old version followed by an addition of the new version.
What is unified diff format?
Unified diff shows changes with context in a single output stream. It starts with --- (old file) and +++ (new file) headers, followed by @@ hunks showing line numbers and the actual changes with +/- prefixes. It's the default format for git diff.
How does Git detect renames in diffs?
Git doesn't track renames explicitly. Instead, it detects renames by comparing deleted files with added files using similarity detection. If a deleted file is sufficiently similar (default 50%) to an added file, Git reports it as a rename.
Can I create a patch from a diff?
Yes. 'git diff > changes.patch' creates a patch file that can be applied to another repository using 'git apply changes.patch'. This is useful for sharing changes without pushing to a shared repository.

Related Guides

Related Tools

Was this page helpful?

Written by

Tamanna Tasnim

Senior Full Stack Developer

ToolsContainerDhaka, Bangladesh5+ years experiencetasnim@toolscontainer.comwww.toolscontainer.com

Full-stack developer with deep expertise in data formats, APIs, and developer tooling. Writes in-depth technical comparisons and conversion guides backed by hands-on engineering experience across modern web stacks.