Skip to content

Git Log — Powerful Commit History Filtering

DodaTech 3 min read

In this tutorial, you'll learn about Git Log. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

What You'll Learn

Master git log — filter commits by author, date, file, message; format output; visualize branches; and find exactly what you need in Git history.

Why It Matters

Git log is your window into project history. Knowing how to filter it effectively saves hours when debugging, auditing, or generating release notes.

Basic Usage

git log                            # Full history
git log --oneline                  # One line per commit
git log --oneline -5               # Last 5 commits
git log --oneline --graph          # Show branch structure
git log --oneline --all            # All branches
git log --oneline --since="2 weeks ago"
git log --oneline --until="2024-01-01"

Filtering by Author

git log --author="Alice"
git log --author="Alice\|Bob"      # Multiple authors
git log --committer="Charlie"      # By committer

# List all contributors
git shortlog -sn
# Alice  42 commits
# Bob    37 commits
# Charlie 12 commits

Filtering by Date

git log --after="2024-01-01"
git log --before="2024-06-01"
git log --after="2 weeks ago"
git log --since="2024-01-01" --until="2024-03-01"
git log --after="yesterday"

Filtering by File or Directory

git log --oneline -- login.py          # Commits touching this file
git log --oneline -- src/              # Commits in this directory
git log --oneline -- "*.js"            # Commits touching JS files
git log --oneline -- src/ -- "*.css"   # Multiple paths

# Follow a file through renames
git log --follow -- login.py

Searching Commit Messages

git log --grep="fix"                    # Commits with "fix" in message
git log --grep="fix\|bug"              # Multiple patterns
git log --grep="security" -i           # Case-insensitive
git log --grep="vulnerability" --oneline --all

Showing Changes (Patch)

git log -p                           # Show full diff for each commit
git log -p -- login.py               # Diff for a specific file
git log --stat                       # Show changed files and stats
git log --shortstat                  # Summary of changes
git log --name-only                  # Only list changed files
git log --name-status               # + changed files with status

Custom Format

# Custom format string
git log --pretty=format:"%h - %an, %ar : %s"

# Common placeholders:
# %h  = abbreviated commit hash
# %H  = full commit hash
# %an = author name
# %ae = author email
# %ad = author date
# %ar = relative date
# %s  = subject
# %d  = ref names (branches, tags)
# %b  = body

Branch and Merge Visualization

# Show branch topology
git log --oneline --graph --all --decorate

# Show first-parent ancestry (skip merge commits)
git log --first-parent --oneline

# Show only merge commits
git log --merges
git log --no-merges       # Exclude merge commits

Finding Lost Commits

# Search all refs (including ones no longer reachable)
git log --oneline --all --grep="WIP"

# Search reflog
git reflog
git log --oneline -g      # Walk reflog entries

Statistics and Reports

# Who changed the most lines this month?
git log --after="1 month ago" --format='%an' | sort | uniq -c | sort -rn

# Total commits per author
git shortlog -sn

# Files changed most often
git log --pretty=format: --name-only | sort | uniq -c | sort -rn | head -20

# Commit activity per day of week
git log --date=format:"%a" --format="%ad" | sort | uniq -c | sort -rn

Quick Reference

Command What It Shows
git log --oneline -5 Last 5 commits, one line each
git log --author="Alice" Commits by Alice
git log --since="1 week ago" Commits from this week
git log -- src/ Commits touching src/
git log --grep="fix" Commits mentioning "fix"
git log -p -- login.py Full diff for login.py changes
git log --graph --all Full branch topology
git shortlog -sn Contributor leaderboard

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro