Git Notes
Master git log command for viewing commit history, formatting output, filtering commits, searching repository history, and understanding repository timeline and evolution.
git log displays the commit history of your repository. Essential for understanding how your project evolved and who made what changes.
Basic Usage
git log
# Output:
# commit abc123def456...
# Author: John Doe <john@example.com>
# Date: Mon Jun 13 14:30:45 2026 +0000
# Add user authentication
#
# commit def456ghi789...
# Author: Jane Smith <jane@example.com>
# Date: Sun Jun 12 10:15:20 2026 +0000
# Update database schemaOne-liner View
git log --oneline
# Output:
# abc123d Add user authentication
# def456g Update database schema
# ghi789h Initial project setupLast N Commits
# Last 5 commits
git log -5
# Last 10
git log -10
# Last 1
git log -1Graph View (Branches)
git log --graph --oneline --all
# Output:
# * abc123d Add feature X
# |\
# | * def456g Add feature Y
# |/
# * ghi789h Merge branch
# * ijk012l Initial commitCustom Format
# Pretty format
git log --pretty=format:"%h - %an, %ar : %s"
# Output:
# abc123d - John Doe, 2 hours ago : Add user auth
# def456g - Jane Smith, 1 day ago : Update schema
# Format codes:
# %h = commit hash (short)
# %an = author name
# %ae = author email
# %ar = author date, relative
# %s = subject (message)
# %b = bodyFilter by Author
# Commits by specific person
git log --author="John Doe"
# Output shows only John's commitsFilter by Date
# Last week
git log --since="1 week ago"
# Between dates
git log --since="2 weeks ago" --until="1 week ago"
# Specific date
git log --since="2026-06-01" --until="2026-06-13"Search in Messages
# Commits containing word
git log --grep="feature"
# Case insensitive
git log --grep="Feature" -i
# Find commits mentioning "auth"
git log --grep="auth"Search in Code
# Find commits that added/removed text
git log -S "searchtext"
# Find where variable was introduced
git log -S "const apiKey"
# Show diff for results
git log -p -S "searchtext"View Changes in Log
# Show changes in each commit
git log -p
# Show only summary
git log --stat
# Specific file history
git log path/to/file.jsBlame (Who Changed What)
# See who changed each line
git blame file.js
# Output:
# abc123d (John Doe 2026-06-13) function getData() {
# def456g (Jane Smith 2026-06-10) return fetch('/api');
# ghi789h (John Doe 2026-06-05) }Useful Combinations
# Pretty one-liners with dates
git log --oneline --date=short --pretty=format:"%h %ad %s"
# Author contribution summary
git log --all --oneline --no-merges --author="John"
# Commits in last day
git log --since="24 hours ago" --onelineComparing Branches
# Commits in branch1 but not branch2
git log branch2..branch1
# Commits on both branches
git log --all --graph --onelineInterview Q&A
Q1: Common git log commands and when to use each?
A: git log --oneline for quick overview. git log -p to see actual code changes. git log --graph --oneline --all to understand branch structure. git log --author="name" to see specific person's work. git log --since="1 week ago" for recent changes. git log -S "text" to find when code was added.
Q2: How to find who made specific change?
A: Use git log -p -S "text" to find commits containing text. Use git blame filename to see who changed each line. Use git log --author="name" to see specific person's commits. Combine with grep: git log --grep="keyword".
Q3: Difference between git log --author and git blame?
A: git log --author shows all commits by person across repository. git blame shows for each line: who changed it, when, in which commit. Use author for "what did person X do?" Use blame for "who changed this line and why?"
Q4: How to view commits between two branches?
A: Use git log branch1..branch2 to see commits in branch2 but not branch1. Use git log branch1...branch2 to see commits in either but not both. Use git log --graph --oneline --all to visualize both branches.
Q5: What's the most useful git log format?
A: Many prefer: git log --oneline --graph --all for quick visualization of branches and commits. Or create alias: git config alias.lg "log --graph --oneline --all" then just git lg. For detailed: git log -p shows actual code changes. For code archaeology: git log -S "text" finds when code appeared.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Git Log - View Commit History.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Git & GitHub topic.
Search Terms
git-github, git & github, git, github, basics, log, git log - view commit history
Related Git & GitHub Topics