Basic Log Commands
Display commit history.
git log
Compact one-line format:
git log --oneline
Show last N commits:
git log -n 5
Formatted Logs
Show log with graph visualization.
git log --graph
Detailed graph with branch names:
git log --graph --oneline --decorate --all
Custom format:
git log --pretty=format:"%h - %an, %ar : %s"
Filter by Date
Show commits since specific date.
git log --since="2 weeks ago"
Show commits until date:
git log --until="2024-01-01"
Show commits in date range:
git log --since="2024-01-01" --until="2024-12-31"
Filter by Author
Show commits by specific author.
git log --author="John Doe"
Multiple authors:
git log --author="John\|Jane"
Filter by Message
Search commits by message content.
git log --grep="bug fix"
Case-insensitive search:
git log --grep="feature" -i
Show File Changes
Display files changed in each commit.
git log --stat
Show full diff in each commit:
git log -p
Show changes for specific file:
git log -p <filename>
Show Commits for File
View commit history for specific file.
git log -- <filename>
Follow renames:
git log --follow -- <filename>
Show Commits in Range
Display commits between two references.
git log <branch1>..<branch2>
Show commits in branch1 not in branch2:
git log branch1 ^branch2
Show Who Changed Lines
Display who last modified each line.
git blame <filename>
Show specific line range:
git blame -L 10,20 <filename>
Reference Log
Show history of HEAD movements.
git reflog
Show reflog for specific branch:
git reflog show <branch-name>
Search Code History
Find when specific string was added or removed.
git log -S "search string"
Search with regex:
git log -G "regex pattern"
Show Merge Commits
Display only merge commits.
git log --merges
Exclude merge commits:
git log --no-merges
Shortlog Summary
Summarize commits by author.
git shortlog
Show commit counts:
git shortlog -sn