← Back to all tutorials

Viewing the Project History

Learn about Viewing the Project History

One of Git's greatest powers is its complete, searchable project history. Every commit is recorded with who made it, when, and exactly what changed. This episode shows you how to explore, search, and understand your project history like a detective.

git log — The History Book

# Full commit log
git log

# Compact one-line format (most useful daily)
git log --oneline

# Show last N commits
git log -5

# Log with file changes listed
git log --stat

# Log with full diff (actual code changes)
git log -p

# Log for a specific file
git log -- README.md
git log --oneline -- src/app.js

Pretty Formatting

# Graph view — shows branch structure visually
git log --oneline --graph --all

# Custom format
git log --pretty=format:"%h %an %ar - %s"
# %h = short hash, %an = author name, %ar = relative date, %s = subject

# Example output:
# a1b2c3d John 2 hours ago - Fix login bug
# e4f5g6h Jane 1 day ago - Add dashboard page
# i7j8k9l John 3 days ago - Initial commit

Filtering History

# Commits by author
git log --author="John"

# Commits in a date range
git log --after="2024-01-01" --before="2024-06-30"

# Commits containing a keyword in the message
git log --grep="fix"
git log --grep="login" --oneline

# Commits that changed a specific string in code
git log -S "function calculateTotal"
# Shows commits where "function calculateTotal" was added or removed

git show — Inspect a Commit

# Show full details of a commit
git show a1b2c3d

# Show a specific file at a specific commit
git show a1b2c3d:src/app.js

# Show the latest commit
git show HEAD

git diff — Compare Changes

# Changes in working directory (not yet staged)
git diff

# Changes that are staged (ready to commit)
git diff --staged

# Compare two commits
git diff a1b2c3d e4f5g6h

# Compare a file between two commits
git diff a1b2c3d e4f5g6h -- src/app.js

# Compare current branch with another branch
git diff main..feature/login

# Show only file names that changed
git diff --name-only a1b2c3d e4f5g6h

git blame — Who Changed This Line?

# Show who last modified each line
git blame index.html

# Blame a specific range of lines
git blame -L 10,20 src/app.js

# Output shows:
# a1b2c3d (John 2024-01-15  10) function login() {
# e4f5g6h (Jane 2024-02-01  11)   const email = getEmail();
# a1b2c3d (John 2024-01-15  12)   validate(email);
# i7j8k9l (Bob  2024-03-10  13)   // Added rate limiting

git shortlog — Contributor Summary

# Commits grouped by author
git shortlog

# Count only
git shortlog -s -n
# Output:
#   42  John
#   35  Jane
#   18  Bob

What's Next

You can now read and search through your project's entire history. In the next episode, we'll learn how to undo changes — from discarding uncommitted edits to reverting entire commits.