Schematische Diff-Ansicht: links die alte Dateiversion, rechts die neue; dazwischen ein Ausschnitt mit rot markierten Minus-Zeilen für Löschungen, grün markierten Plus-Zeilen für Hinzufügungen und grauen Kontextzeilen darüber und darunter.

Code Diff

A code diff is a side-by-side comparison that shows which lines of a file have changed between two versions. Developers use it to review changes, and AI assistants often present their suggestions in exactly this form.

Programs consist of text files in which instructions appear line by line. When someone works on them, usually only a tiny part of the file actually changes. A code diff is a representation that makes exactly this difference between two versions of a file visible. It shows which lines were removed and which were newly added, largely leaving out everything that stayed the same. On screen, removed lines are typically marked red with a minus sign, new ones green with a plus sign. The name comes from the English word difference.

Why nobody reads a thousand lines twice

A larger software project quickly comprises hundreds of thousands of lines. Nobody can reread the entire file for every single change. The diff reduces the review to what has actually moved. A file with 2,000 lines thus becomes a view with maybe twelve affected lines.

A fixed workflow builds on this: code review. Before a change is merged into the shared project, at least one other person looks at it. This person almost always reads the diff, not the full code. Bugs, security vulnerabilities, and accidental deletions are caught this way before they reach users.

The diff is also a record. For every change in the project’s history, it can later be traced who touched which line and when. When a piece of software suddenly stops working, people search specifically through the most recent diffs. Often the bug is found within minutes instead of hours.

How the line-by-line comparison is created

A diff program is given two versions of a text and looks for the longest common sequence of lines. Everything within this common sequence is considered unchanged. Whatever appears only in the old version is marked as a deletion. Whatever appears only in the new version counts as an addition. A changed line is thus technically not a separate case, but a deletion plus an addition.

To keep the view readable, the common format additionally shows three unchanged lines above and below each change. This surrounding area is called context. Such a coherent section is called a hunk. A header line within it indicates the line number at which the section begins in both versions.

A common misconception: a diff does not describe meaning, only text. If someone moves a function to a different location within the file, the tool sees one large deletion and one large addition. Nothing has actually changed in terms of content, yet the diff looks dramatic. Modern tools mitigate this by detecting moves or by highlighting differences within a single line in color.

Diffs in AI assistants and in tech news

Anyone developing software together with others typically uses the version control system Git, a system that stores all intermediate states of a project. Platforms like GitHub or GitLab display every proposed change there as a diff with green and red lines. This is exactly the view outsiders also see when a news report mentions a submitted patch.

In the AI world, the diff has become the standard format for programming assistants. Tools like GitHub Copilot or Claude Code do not output their suggestions as a complete new file, but as a change block. This saves computing effort and makes the suggestion reviewable. The human sees at a glance what the model wants to touch, and confirms or rejects it.

The evaluation of such systems also relies on diffs. In the well-known SWE-bench test, a model receives real bug reports from open-source projects and must generate a matching patch. What is measured is whether the software then passes the test programs. When news reports mention percentage scores on such benchmarks, they are essentially talking about the quality of automatically generated code diffs.

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.