Viewing Commit History
Every commit you make becomes part of your project's permanent history. The git log command lets you explore this timeline — seeing what changed, when, and who made each change. Understanding your history helps you track down bugs, understand decisions, and navigate your project's evolution.
Viewing the Full Log
Run git log to see your commit history:
Each entry shows:
- Commit hash: A unique identifier (like
abc1234def5678) - Author: Who made the commit
- Date: When it was made
- Message: What the commit describes
The log shows commits in reverse chronological order — newest first.
Navigating the Log
If your history is long, Git displays it in a pager. Press Space to scroll down, b to scroll up, and q to quit and return to your terminal. This is the same navigation used by the less command.
A Compact View
For a quicker overview, use the --oneline flag:
This shows just the short hash and message — perfect for scanning through history quickly.
Understanding Commit Hashes
Every commit has a unique identifier called a hash — a long string like abc1234def5678901234567890abcdef12345678. You can reference commits by their full hash or just the first several characters (Git figures out which commit you mean).
These hashes let you:
- Return to a specific point in history
- Compare different versions
- Reference commits in discussions
Limiting the Output
View only recent commits with -n:
git log -n 5 # Show last 5 commits
Or see commits that touched a specific file:
git log hello.py # Show commits affecting hello.py
Seeing What Changed
To see the actual changes in each commit, add -p:
git log -p
This shows the "diff" — lines added and removed — for each commit. It's verbose but useful when you need to understand exactly what changed.