Skip to content

log Git Command Guide

The git log command displays the commit logs for a repository, showing commit information in reverse chronological order. It provides comprehensive history browsing with formatting options, filtering capabilities, and detailed commit information display.

Terminal window
git log [<options>] [<revision-range>] [[--] <path>...]
OptionDescription
--onelineCondensed format: abbreviated hash and title
--shortShorter format than default
--fullFull format (default)
--fullerEven more information
--rawShow raw commit information
--graphDisplay ASCII graph of branch structure
`—decorate[=shortfull
--statShow diff statistics
--numstatShow numeric diff statistics
--shortstatShow summary of changes
--name-onlyShow only names of changed files
--name-statusShow names and status of changed files
OptionDescription
-<n>Show only last n commits
--since=<date>Show commits more recent than date
--until=<date>Show commits older than date
--author=<pattern>Show commits by authors matching pattern
--committer=<pattern>Show commits by committers matching pattern
--grep=<pattern>Show commits with messages matching pattern
--all-matchShow only commits matching all —grep
--invert-grepShow commits not matching —grep
-S<string>Show commits changing the number of occurrences
-G<regex>Show commits whose diff matches regex
--followFollow file renames
--no-mergesDon’t show merge commits
--mergesShow only merge commits
--first-parentFollow only first parent of merges
--notReverse the meaning of ^ prefix
--allShow all refs
OptionDescription
--pretty=<format>Pretty-print with format
--format=<format>Alias for —pretty=format
--abbrev-commitShow abbreviated commit hash
--no-abbrev-commitDon’t abbreviate hash
--onelineShortcut for —pretty=oneline —abbrev-commit
--encoding=<encoding>Re-encode commits to encoding
ParameterDescription
<revision-range>Range of commits to show (e.g., master..feature)
<path>...Show only commits affecting these paths
Terminal window
# Show recent commits in default format
git log
# Show last 5 commits
git log -5
# Show commits in compact format
git log --oneline
Terminal window
# Show branch structure with graph
git log --oneline --graph --all
# View merge history
git log --graph --oneline --first-parent
Terminal window
# Commits from last week
git log --since="1 week ago"
# Commits from specific date range
git log --since="2023-01-01" --until="2023-12-31"
# Commits by date with author
git log --since="2 months ago" --author="John"
Terminal window
# Commits mentioning specific text
git log --grep="fix"
# Case-insensitive search
git log --grep="FIX" -i
# Commits by author pattern
git log --author=".*@company.com"
Terminal window
# Commits affecting specific file
git log --follow -- src/main.c
# Commits in directory
git log -- src/
# Multiple files
git log -- README.md CHANGELOG.md
Terminal window
# Custom format
git log --pretty=format:"%h %s %d"
# Full custom format
git log --pretty=format:'%C(yellow)%h%Creset %Cgreen%ad%Creset %s %Cblue%an%Creset %Cred%d%Creset' --date=short
# Include trailers
git log --pretty=format:"%h %s%n%(trailers:unfold,key=Signed-off-by,valueonly)"
Terminal window
# Show file changes summary
git log --stat
# Show numerical statistics only
git log --numstat
# Overall statistics
git log --shortstat
Terminal window
# Show all references
git log --oneline --all --graph
# Compare branches
git log --oneline master..feature-branch
# Find branching point
git log --oneline --merges master
Terminal window
# Detailed author information
git log --format='%aN <%aE>' | sort | uniq -c | sort -rn
# Committer vs author differences
git log --format='%an vs %cn' --all-match --grep="Co-authored-by"
# Recent contributors
git log --since="6 months ago" --format='%aN' | sort | uniq
Terminal window
# Commits starting with certain patterns
git log --grep="^feat\|fix\|docs\|style\|refactor\|test\|chore" --oneline
# Breaking changes
git log --grep="BREAKING\|breaking" --oneline
# Issue tracker links
git log --grep="#[0-9]\+" --oneline
Terminal window
# Only merge commits
git log --merges --oneline
# Exclude merges
git log --no-merges --oneline
# First parent path (main branch development)
git log --first-parent --oneline
Terminal window
# See changes for review
git log --oneline --stat origin/main..HEAD
# Detailed diff for reviewer
git log -p --reverse origin/main..HEAD
# Summary for release notes
git log --oneline --grep="feat\|fix\|docs" origin/v1.0..HEAD
Terminal window
# Find commits affecting file around date
git log --since="2023-01-01" --until="2023-01-31" -- src/file.c
# Find commits changing specific string
git log -S"bug" --oneline
# Find commit introducing regex pattern
git log -G"TODO|FIXME" --oneline
Terminal window
# Generate changelog
git log --oneline --format="* %s (%h)" v1.0..HEAD
# Version bump commits only
git log --grep="bump\|version\|release" --oneline
# Feature additions since release
git log --grep="^feat" --oneline tag/v1.0.0..HEAD
Terminal window
# Most active contributors
git log --format='%aN' | sort | uniq -c | sort -nr | head -10
# Commits by week
git log --date=short --format='%ad' | cut -d- -f1-2 | sort | uniq -c
# Productivity metrics (commits per day)
git log --date=short --format='%ad' | sort | uniq -c | awk '{print $2 ": " $1 " commits"}'
Terminal window
# Limit depth for speed
git log --oneline -100
# Specific time range for analysis
git log --since="3 months ago" --oneline
# Path-limited search
git log -- src/lib/ --oneline
Terminal window
# Efficient author searching
git log --format='%H %aE %aN' --all | awk '/@company.com/ {print $1}' | xargs git show --stat
# Batch processing commits
git log --format='%H' --oneline | head -50 | xargs -I {} sh -c 'git show --name-only {} | head -20'
Terminal window
# Export for project management
git log --format='%H|%an|%ae|%s|%(trailers:key=Fixes,valueonly)' > commits.csv
# Feed to ticket system
git log --grep="#[0-9]\+" --format='%H %s' | while read hash msg; do
ticket=$(echo "$msg" | grep -o '#[0-9]\+')
echo "Commit $hash affects ticket $ticket"
done
#!/bin/bash
# Generate deployment notes
git log --oneline --format="* %s (%aN)" origin/main..HEAD > deploy-notes.txt
# Validate commit standards
if ! git log --format='%s' -1 | grep -q "^(feat|fix|docs|style|refactor|test|chore):"; then
echo "Commit message doesn't follow conventional commits"
exit 1
fi
Terminal window
# Colored output
git log --color --oneline
# Configure colors
git config color.log.date yellow
git config color.log.author blue
Terminal window
# Configure pager
git config core.pager "less -FRSX"
git config pager.log "true"
# Disable pagination for scripts
git --no-pager log --oneline | head -10
Terminal window
# Check if in repository
git status
# Check current branch commits
git log --oneline HEAD
# See all branches
git log --all --oneline | head -10
Terminal window
# Time-consuming operations
time git log --all --graph
# Optimize with caching
git config core.logAllRefUpdates true
Terminal window
# Fix character encoding
git log --encoding=UTF-8
# Configure repository encoding
git config i18n.logOutputEncoding UTF-8
Terminal window
# Verify file exists in history
git log --follow -- missing-file.txt 2>/dev/null || echo "File not in history"
# Check case sensitivity
git log --follow -- 'path/file.txt'

Creates ASCII visualization of commit ancestry, showing branches, merges, and commit relationships through text characters connecting related commits.

What’s the difference between —stat and —shortstat?

Section titled “What’s the difference between —stat and —shortstat?”

—stat shows per-file statistics with +/- counts; —shortstat shows only repository-level summary (files changed, insertions, deletions).

Follows only first parent of merges, showing mainline development while hiding merged feature branches - useful for understanding deployment timeline.

Use %(trailers) format specifier to display or process commit message trailers separately from main commit message.

What’s the performance cost of —follow?

Section titled “What’s the performance cost of —follow?”

Follows file renames across entire repository history - expensive for large repos, suitable for single file analysis only.

Shows file was modified but doesn’t display binary diff. Use —name-only to see which binaries changed without content display.

Reverses normal chronological order, showing oldest commits first - useful for recreating development timeline or chronological analysis.

What’s the difference between —author and —committer?

Section titled “What’s the difference between —author and —committer?”

Author is who wrote the code, committer is who created the commit. Different in patch workflows where someone applies another’s changes.

Yes, combine with path patterns: git log — ‘.c’ ‘.h’ for only C source files, or use —name-only with grep for post-filtering.

How do I see only commits changing specific lines?

Section titled “How do I see only commits changing specific lines?”

Use git log -L ,: to show changes to specific line range. Shows commits affecting specified lines in the file.

Shows commits reachable from but not from while maintaining path between commits - useful for complex merge analysis.

git log shows committed history; git reflog shows local reference changes including resets, rebases, amendments - broader than permanent history.

  1. Development Monitoring: Track code evolution and contributor activity over time
  2. Bug Investigation: Trace when bugs were introduced and through which commit paths
  3. Code Review Facilitation: Prepare comprehensive change summaries for review teams
  4. Release Preparation: Generate changelogs and validate release candidate contents
  5. Team Collaboration: Share repository history and coordinate development activities
  6. Compliance Auditing: Verify change history for regulatory and quality requirements