All courses

git status and reading a diff

Use `git status` to see which files changed and `git diff` to see exactly how. Read a unified diff's '-', '+' and '@@' lines without help.

Builds on: Git commits as snapshots you can return to

Read it card by card Start the whole course

Something changed. What exactly?

You let an agent work in your project for a few minutes. It ends with: ◂ Agent: Done. Fixed the crash in the cart total. You made a commit before it started, so you can go back. But before you decide anything, you need two facts: which files did it actually touch, and what exactly is different inside them? Its message only describes the work. It does not show you the files.

Git compares now with your last snapshot

Your last commit is a saved snapshot. Git can compare the files on disk right now with it. `git status` gives the short answer: *which* files differ. It also lists new files git has never saved (**untracked**). `git diff` gives the long answer: *which lines* differ inside files git already tracks. One exception, staging, comes on the next card. Think of status as the table of contents and diff as the pages. Neither command changes anything, so run them as often as you like.

Reading git status and git diff

Run from inside the project: - `git status`: `modified:` and `deleted:` are changed tracked files. **Untracked files** are brand-new; `git diff` skips them, so open them yourself. - **Staged** means marked with `git add` to go into the next commit. Status lists these under **Changes to be committed** and the rest under **Changes not staged for commit**. - `git diff`: unstaged line changes. `git diff --staged`: staged ones. `git diff <file>`: one file only. - `-` removed, `+` added, unmarked = unchanged context. - Long output opens in a pager: space scrolls, `q` quits.

Walking through one real change

`git status` lists `modified: src/cart.py` and an untracked `notes.txt` you never asked for. Open that file yourself. Then run `git diff` (next card). `@@ -2,5 +2,6 @@` means this section starts at line 2. It is 5 lines long in the old file and 6 in the new one. One `-` line and two `+` lines: `s += it.price` now runs only when the price is not `None`. So the fix *skips* unpriced items. Did you want that?

The diff behind "fixed the crash"

Skip the `diff --git` and `index` lines: they are git's bookkeeping. `--- a/` names the old `src/cart.py` and `+++ b/` names the new one. These two lines are file names, not removed or added lines. The text after the second `@@` is git naming the function this section sits in. A changed line usually appears as a `-` line followed by its `+` replacement.
diff --git a/src/cart.py b/src/cart.py
index 3b18e51..a1c2d4f 100644
--- a/src/cart.py
+++ b/src/cart.py
@@ -2,5 +2,6 @@ def total(items):
     """Sum item prices."""
     s = 0
     for it in items:
-        s += it.price
+        if it.price is not None:
+            s += it.price
     return s

Status for which, diff for how

`git status` tells you which files changed and which are new. `git diff` shows exactly how, line by line: `-` removed, `+` added, unmarked = context, and `@@` = where each section starts. Read those yourself instead of taking a summary's word for what changed.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.