Skip to content
Justice Tech School

Diff

git diff shows unstaged changes, git diff --staged shows what will be committed, and git diff A B compares two commits or branches. Lines starting with + were added and - were removed.

Example
printf "one\ntwo\n" > f.txt
git add f.txt; git commit -q -m "init"
printf "one\nTWO\nthree\n" > f.txt
git diff --stat | head -1
git diff | grep "^[+-][^+-]"
git add f.txt
git diff --staged --stat | tail -1

Result

 f.txt | 3 ++-
-two
+TWO
+three
 1 file changed, 2 insertions(+), 1 deletion(-)

Exercise

Show staged changes.

git diff 

Quiz Test

What does a + line in a diff mean?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.