AI Hints
Home›Git & GitHub Tutorial›Seeing Changes
Git & GitHub · Lesson 16 of 144

Seeing Changes

Git diff.

⏱ 2 min read▶ Video at 16:11🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

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.

Seeing Changes
From the video: Seeing Changes
  • 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
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.

keyvalue
diff --git a/ b/which file
@@ ... @@where in the file
- in redremoved line
+ in greenadded 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
Next up: Diffing Staged Changes — git diff --staged