Viewing History
The git log command shows the commit history of your repository.
Basic Log
Log Formats
Default Format
git log
Shows full commit details with hash, author, date, and message.
One Line Format
git log --oneline
Shows abbreviated hash and first line of message.
Graph View
git log --oneline --graph
Shows branch structure visually.
Common Options
| Option | Description |
|---|---|
--oneline | Compact format |
--graph | ASCII branch graph |
-n <num> | Limit to n commits |
--since="2 weeks ago" | Date filter |
--author="name" | Filter by author |
--grep="pattern" | Search messages |
-p | Show patches (diffs) |
--stat | Show file stats |
Examples
Last 5 Commits
git log -5
Commits by Author
git log --author="Alice"
Commits with Stats
git log --stat
Pretty Formats
git log --pretty=format:"%h %s (%an)"
Format placeholders:
%h- Short hash%H- Full hash%s- Subject%an- Author name%ar- Relative date
Viewing Specific Commits
git show HEAD # Latest commit
git show HEAD~1 # Previous commit
git show abc1234 # Specific commit
Log for Specific Files
git log -- filename.txt
git log -p -- filename.txt # With changes
Exercise: View Commit History
Use git log --oneline to see a compact history:

