Terminal GuideTerminal Guide

git log Command Guide

Show commit logs

8 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

git logShow commit history
git log --onelineOne line per commit
git log -n 5Show last 5 commits

Format

--graphASCII branch graph
--statShow file changes
-pShow full diff

Filter

--author="name"By author
--since="2024-01-01"Since date
-- path/fileFile history

Downloadable Image Preview

Failed to generate preview

Basic Usage

The git log command shows the commit history. It's essential for understanding what changes were made and when.

bash
# Show full commit history
git log

# Compact one-line format
git log --oneline

# Show last 5 commits
git log -5

Formatting Output

bash
# One line per commit
git log --oneline

# With branch/merge graph
git log --graph --oneline

# With file statistics
git log --stat

# With full diff
git log -p

# Combined: graph + oneline + all branches
git log --graph --oneline --all

# Decorated (show branch/tag names)
git log --oneline --decorate

Useful Aliases

bash
git config --global alias.lg "log --graph --oneline --decorate --all"
git config --global alias.lol "log --oneline -20"

Filtering Commits

bash
# By author
git log --author="John"

# By date range
git log --since="2024-01-01" --until="2024-06-01"
git log --after="2 weeks ago"

# By commit message
git log --grep="fix bug"
git log --grep="fix" -i  # Case insensitive

# By file
git log -- src/app.js
git log -p -- src/app.js  # With diff

# By content change
git log -S "functionName"  # When function was added/removed
git log -G "regex"         # Regex match in changes

# Range of commits
git log main..feature      # Commits in feature not in main
git log main...feature     # Commits in either, not both

Custom Format

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

# Format placeholders:
# %H  - Full commit hash
# %h  - Abbreviated hash
# %an - Author name
# %ae - Author email
# %ar - Author date, relative
# %ad - Author date
# %s  - Subject (first line)
# %b  - Body

# Examples
git log --pretty=format:"%h %ad | %s [%an]" --date=short
git log --pretty=format:"%C(yellow)%h%C(reset) %s %C(blue)<%an>%C(reset)"

Practical Examples

bash
# Quick history overview
git log --oneline -20

# See what changed in each commit
git log --stat

# Full history with graph
git log --graph --oneline --all --decorate

# File history
git log -p -- README.md

# Who changed what in the last week
git log --since="1 week ago" --author="$(git config user.name)"

# Find when a function was added
git log -S "myFunction" --source --all

# Commits between releases
git log v1.0..v2.0 --oneline

# Merge commits only
git log --merges

# Exclude merge commits
git log --no-merges

Frequently Asked Questions

How do I see the history of a specific file?

Use "git log -- <filename>" to see only commits that affected that file. Add -p to see the actual changes: "git log -p -- filename".

How do I find commits by a specific author?

Use "git log --author="name"" to filter by author. You can use partial names or email addresses.

How do I search commit messages?

Use "git log --grep="pattern"" to search commit messages. Add -i for case-insensitive search.

How do I see a graph of branches?

Use "git log --graph --oneline --all" to see an ASCII graph of all branches and their relationships.

How do I see changes between two commits?

Use "git log commit1..commit2" to see commits between two points. Use "git log main..feature" to see commits in feature not in main.

Summary

git log is your window into project history. Combine filters and formatting for exactly the information you need.

Quick Reference

  • git log --oneline - Compact view
  • git log --graph - Branch graph
  • git log -p - With diffs
  • git log -- <file> - File history

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles