CSE Roadmap

Common tier · about 5 hours · 11 parts

Part 6 of 11 · 3 min read

Reading a diff

How to read the output of git diff, and how to review someone else's change in a sensible order.

You have already met git diff in Part 3. Reading diffs is the skill you will use most on a team, because every pull request is a diff that someone has to understand before approving it.

Diff

Short for difference: a list of the lines that changed between two versions of the same files. It shows what was removed, what was added, and a little unchanged text around each change so that you can see where it happened.

Here is a real diff. A file settings.txt had timeout = 15, and we changed it to timeout = 20:

diff --git a/settings.txt b/settings.txt
index bcfa5ce..756caa4 100644
--- a/settings.txt
+++ b/settings.txt
@@ -1,2 +1,2 @@
-timeout = 15
+timeout = 20
 retries = 3
AAAWgmp1bWIAAAAeanVtZGMycGEAEQAQgAAAqgA4m3EDYzJwYQAAABZcanVtYgAAAEdqdW1kYzJtYQARABCAAACqADibcQN1cm46YzJwYToyNTNlMDcxZC05OTAwLTQzM2MtYjNiZi02Y2Y5MzU2NDM5NzYAAAADl2p1bWIAAAApanVtZGMyYXMAEQAQgAAAqgA4m3EDYzJwYS5hc3NlcnRpb25zAAAAALxqdW1iAAAARGp1bWRjYm9yABEAEIAAAKoAOJtxE2MycGEuaW5ncmVkaWVudC52MwAAAAAYYzJzaE/NDJuzPdDrU08yPwBYZ9cAAABwY2JvcqNpZGM6Zm9ybWF0bWltYWdlL3N2Zyt4bWxqaW5zdGFuY2VJRHgseG1wOmlpZDo5NThlNzJhMy1kNTcwLTQxY2QtODJlMy1kMGIwM2I3YjgwOWJscmVsYXRpb25zaGlwaHBhcmVudE9mAAAB4mp1bWIAAABBanVtZGNib3IAEQAQgAAAqgA4m3ETYzJwYS5hY3Rpb25zLnYyAAAAABhjMnNoMDND6FXDIJUagK8AvUj8agAAAZljYm9yomdhY3Rpb25zgqJmYWN0aW9ua2MycGEub3BlbmVkanBhcmFtZXRlcnOha2luZ3JlZGllbnRzgaJjdXJseC1zZWxmI2p1bWJmPWMycGEuYXNzZXJ0aW9ucy9jMnBhLmluZ3JlZGllbnQudjNkaGFzaFgg8mMuN4Su5jw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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZYQLtEF0uSMEGQXaJubBgJYuag5+nUH87a7RrI8UZzFENGiZIaxeykCqHP4itZ1jT7xD5pBrXZQjfZty74mYFZcCY= diff --git a/app/client.py b/app/client.py --- a/app/client.py +++ b/app/client.py @@ -12,6 +12,9 @@ def fetch(url): headers = auth_headers() - r = httpx.get(url, headers=headers) + r = httpx.get(url, headers=headers, + timeout=10.0) + r.raise_for_status() return r.json() 1 Which file2 Which lines3 Removed4 Added5 Context a/ is before, b/ is afterold: 6 lines from line 12new: 9 lines from line 12lines starting with -lines starting with +unchanged, for orientation
The five parts of a diff. Learn to find them in seconds.

Read it from the top:

  • diff --git a/settings.txt b/settings.txt names the file. a/ is the old version and b/ is the new one.
  • index bcfa5ce..756caa4 100644 holds short IDs of the two versions of the file and its permissions. You can ignore this line.
  • --- a/settings.txt and +++ b/settings.txt say which side is "old" (---) and which is "new" (+++).
  • @@ -1,2 +1,2 @@ is the hunk header. A hunk is one cluster of changes. -1,2 means "in the old file, starting at line 1, two lines are shown", and +1,2 means the same for the new file.
  • The lines below it are the content. A line starting with - was removed, a line starting with + was added, and a line starting with a space is unchanged context. Changing a line always appears as one removal followed by one addition.

How to review a change

A reviewer does not read every line with equal attention. When a teammate opens a pull request, work in this order:

  1. Read the title and description. What is the change supposed to do?
  2. Look at the list of files. Does it match the description? Files that have nothing to do with it are a warning sign.
  3. Read the tests first. They show what the author believes the code does.
  4. Read the code. For each hunk ask: what happens when this fails, when the input is empty, or when it is very large?
  5. Look for what is missing. A new endpoint with no test for failure, a retry with no limit, a log line that prints a secret.

Reviewing agent changes

In an agent project, a one-line edit to a system prompt, a tool description or a model name can change behaviour more than a hundred lines of code, and no test may fail. Review those lines as seriously as code, and ask for an example run or an evaluation result in the pull request. In Level 9 you will automate that check.

Check yourself

  • In a diff, what does a line starting with - mean? And one starting with a space?
  • What is a hunk?
  • Why read the tests before the code?