Git & Command Line Tutorial · Git Basics · Lesson 10 of 20

Viewing History and Differences

Explore history with git log, see exactly what changed with git diff and git show, and find who changed a line with git blame.

Create a free account to save this page, take notes and track your progress. Sign in

git log

  • git log shows commits, newest first; --oneline one per line; --graph --all draws branches; -p includes the changes; --stat lists changed files.
  • Filter: git log --author=Ana, --since="2 weeks ago", -- path/to/file, -S "functionName" (commits that added or removed that text).

git diff and git show

  • git diff: unstaged changes. git diff --staged: what's staged for the next commit.
  • git diff main..feature: differences between branches.
  • git show <commit>: one commit's message and changes.
  • git blame file: who last changed each line, and in which commit.
diff, log --stat, show and blame
git init -b main --quiet notes && cd notes
printf "line one\nline two\n" > todo.txt
git add todo.txt && git commit -m "Start todo list" --quiet
printf "line one\nline 2 (edited)\nline three\n" > todo.txt
git commit -am "Edit and extend todo list" --quiet
echo "line four" >> todo.txt

echo "--- unstaged changes:"
git diff
echo "--- history with stats:"
git log --stat --format="%h %s" | sed '/^$/d'
echo "--- the first commit:"
git show --format="%h %an: %s" --stat HEAD~1 | sed '/^$/d'
echo "--- who wrote each line:"
git blame --date=short HEAD -- todo.txt | cut -c1-60   # committed lines only

Output

--- unstaged changes:
diff --git a/todo.txt b/todo.txt
index b11b8b4..41369c8 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,3 +1,4 @@
 line one
 line 2 (edited)
 line three
+line four
--- history with stats:
c795a68 Edit and extend todo list
 todo.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
337024a Start todo list
 todo.txt | 2 ++
 1 file changed, 2 insertions(+)
--- the first commit:
337024a Ana Dev: Start todo list
 todo.txt | 2 ++
 1 file changed, 2 insertions(+)
--- who wrote each line:
^337024a (Ana Dev 2026-01-15 1) line one
c795a68e (Ana Dev 2026-01-15 2) line 2 (edited)
c795a68e (Ana Dev 2026-01-15 3) line three

Run this on your computer — see “Get Started” for setup.

Test yourself

Which command shows the changes you've staged but not yet committed?

  1. git diff
  2. git diff --staged
  3. git log -p
  4. git show
Show answer

Answer: git diff --staged

Was this page helpful?