Lesson 5 of 15

Viewing History & Diffs

Git Log

Git log shows your commit history. There are many formatting options to customize the output.

Example
# Full log
git log

# Compact one-line format
git log --oneline

# Show graph with branches
git log --oneline --graph --all

# Show last 5 commits
git log -5

# Filter by author
git log --author="Alice"

# Filter by date
git log --since="2024-01-01" --until="2024-06-30"

# Search commit messages
git log --grep="fix"

Viewing Diffs

Git diff shows the exact changes between different states of your files.

Example
# Unstaged changes (working vs staging)
git diff

# Staged changes (staging vs last commit)
git diff --staged

# Between two commits
git diff abc123 def456

# Changes in a specific file
git diff -- filename.js

# Summary of changes
git diff --stat

# Show who changed each line
git blame filename.js