How to Read a Unified Diff (---, +++, @@ Explained)

Every git diff, diff -u, or downloaded patch file uses the same compact format - a couple of header lines, a hunk marker, and a handful of line prefixes. Once you know what each piece means, a wall of + and - symbols stops looking cryptic.

Quick answer

--- and +++ label the old and new file at the top. Each @@ -a,b +c,d @@ line is a hunk header giving the starting line number and line count for that chunk in the old file (a,b) and new file (c,d). Below that, a leading space is unchanged context, a leading - is a removed line, and a leading + is an added line.

The header lines (--- a/file, +++ b/file)

--- a/config.txt
+++ b/config.txt

The first two lines identify which file is which. --- always marks the original ("old") version and +++ always marks the revised ("new") version. Everything that follows is described relative to these two files - a removed line came from the --- file, and an added line came from the +++ file.

Hunk headers (@@ -1,4 +1,5 @@ meaning)

@@ -12,4 +12,5 @@

A hunk is one contiguous block of changes. The numbers after - give the starting line number and line count in the old file - here, starting at line 12 for 4 lines. The numbers after + give the same for the new file - starting at line 12 for 5 lines, meaning this hunk has one more line in the new version than the old one (one net addition). A diff can contain multiple hunks if changes are scattered across the file, each with its own @@ ... @@ header.

Line prefixes (space = context, - = removed, + = added)

  • Leading space: a context line - unchanged in both versions, shown only to help you locate the change.
  • Leading -: a line present in the old file that was removed.
  • Leading +: a line present in the new file that was added.

A line that was edited, rather than purely added or removed, shows up as a - line (the old wording) immediately followed by a + line (the new wording) - a diff has no separate concept of "changed," only removed-then-added pairs.

A worked example

--- a/greeting.txt
+++ b/greeting.txt
@@ -1,4 +1,4 @@
 Hello there,
-Thanks for signing up last week.
+Thanks for signing up.
 We're glad to have you.
 See you soon.

Reading this line by line: the hunk starts at line 1 in both files and covers 4 lines on each side. Hello there, is unchanged context. The next line was removed (-Thanks for signing up last week.) and immediately replaced with a new version (+Thanks for signing up.) - together this pair represents one edited sentence. The final two lines are unchanged context again.

How to produce one yourself

diff -u file1.txt file2.txt

From the command line, diff -u produces exactly this format. Inside a git repository, git diff shows the same format for uncommitted changes, or git diff file1 file2 to compare two specific files. If you'd rather skip the terminal, the Text Diff tool's Diff download button generates a standard unified diff file with --- Text A / +++ Text B headers directly from two pasted blocks of text.

Paste your text and download a standard unified diff.

Open Text Diff →

Comparing files in an editor instead?

See how to compare two files in Notepad++, including its diff plugin.

Read the Notepad++ guide →

Frequently Asked Questions

What does @@ mean in a diff?
The @@ ... @@ line is a hunk header - it tells you the starting line number and line count for that chunk of changes, in both the old file and the new file, so you know exactly where in each file the following lines belong.
What do --- and +++ mean at the top of a diff?
--- labels the original (old) file and +++ labels the new (revised) file. Everything below marked with a leading - came from the --- file, and everything marked with a leading + came from the +++ file.
What does a line with no + or - prefix mean?
A line starting with a plain space is a context line - it exists unchanged in both versions and is shown only to help you see where the changes sit relative to the surrounding text. Context lines are never part of the actual change.
How do I produce a unified diff myself?
Run diff -u file1.txt file2.txt from the command line, or git diff inside a git repository to see unified-format changes since the last commit. Both use exactly the same header and prefix format described here.
Can I generate a unified diff without using the command line?
Yes - paste both versions of your text into the Text Diff tool and use the Diff download button. It produces a standard unified diff file with --- Text A / +++ Text B headers that any diff or patch tool can read.
Why do the two numbers in a hunk header sometimes not match?
They represent different things for each side - the old file's starting line and line count, and the new file's starting line and line count. If lines were added, the new file's count is larger; if lines were removed, it's smaller. They only match when the hunk has an equal number of additions and removals.

Share this tool

Featured on ToolDirs
© 2026 ListDiff

Free online list and text processing tools.