Seeing Changes
Git diff.
Git status tells you which files changed. But what exactly changed inside them? For that, we use git diff. It shows the lines you added and removed, before you commit.

- status: which files changed
- diff: what changed inside
- Check before you commit
git diff
In our editor, we changed the welcome line on the home page, and saved the file. Now we run git diff. Lines starting with a minus, in red, were removed. Lines starting with a plus, in green, were added. So we removed welcome, and added welcome to my site. The other lines are just there for context.
git diff diff --git a/index.html b/index.html index 93dd595..7158ae7 100644 --- a/index.html +++ b/index.html @@ -1,3 +1,3 @@ <h1>My Site</h1> -<p>Welcome!</p> +<p>Welcome to my site!</p> <a href="about.html">About</a>
Reading a diff
The top lines name the file. The line with two at signs says where in the file the change is. Then the change itself. Minus means removed, plus means added, and a line with neither stayed the same. A changed line shows up as one removal, and one addition.
| key | value |
|---|---|
| diff --git a/ b/ | which file |
| @@ ... @@ | where in the file |
| - in red | removed line |
| + in green | added line |
Summary
git diff shows exactly which lines you removed and added. Minus is removed, plus is added. Next, a surprise. Diff sometimes shows nothing.
Key takeaways- git diff
- - removed, + added
- Check before committing