Git Log Cheatsheet - Git Commit History Reference

All essential Git Log commands organized by use case, with 48+ entries you can copy and run directly. Find the right command fast when you need it.

Version Control·48 commands·Last updated 2026-07-21
Back to Version Control

Formatting Output 6

git log --oneline
Show commits on a single line
git log -n 10
Show only the last 10 commits
git log --pretty=format:"%h %s"
Custom format: %h short hash, %s subject
git log --graph --oneline --all
Graph all branches
git log --stat
Show file change statistics
git log -p
Show the full diff of each commit

Filtering 10

git log --author="John"
Filter by author
git log --since="2024-01-01"
Filter from a start date
git log --until="2024-06-30"
Filter until an end date
git log --grep="fix"
Filter by commit message regex
git log -i --grep="FIX"
Case-insensitive message filter
git log -- file.js
Show history of a specific file
git log -S "function_name"
Find commits that add/remove a string (pickaxe)
git log -G "regex"
Search diff content by regex
git log --no-merges
Exclude merge commits
git log --first-parent
Follow only the first-parent of the main line

Statistics & Analysis 6

git log --shortstat
Brief stats: files, insertions, deletions
git log --numstat
Per-file insert/delete stats
git log --dirstat
Change proportion by directory
git shortlog -sn
Count commits by author
git shortlog -sne
Count commits by author with email
git log --cherry-pick --right-only main...feature
Show commits unique to a branch

Ranges & Diffs 5

git log main..feature
Commits in feature but not in main
git log HEAD~3..HEAD
Show the last 3 commits
git log origin/main..HEAD
Local commits not yet pushed
git log --cherry-mark main...feature
Mark equivalent commits (=) and unique (+)
git log --left-right main...feature
Mark which side a commit belongs to

File History Tracking 5

git log --follow file.js
Follow history across renames
git log --name-only
Show changed file names per commit
git log --name-status
Show file names and status (A/M/D)
git log --oneline -- file.js
Single-line history of a file
git log -p --follow file.js
Full diff across renames

Format Placeholders 10

%H
Full commit hash
%h
Abbreviated commit hash (--abbrev-commit)
%s
Subject (first line)
%an
Author name
%ae
Author email
%ad
Author date (use --date=short)
%ar
Author relative date (e.g. "2 days ago")
%d
Ref (branch/tag) decoration
%b
Body message
%cn
Committer name

Useful Aliases & Combos 6

git log --oneline --graph --decorate --all
Graph all refs with decorations
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
Common custom log format
git log --since="2 weeks ago" --oneline
Commits from the last two weeks
git log --merges --oneline
Show only merge commits
git config alias.lg "log --graph --oneline --decorate --all"
Set an lg alias, then use git lg
git log --source --oneline
Show the ref each commit came from

💡 Tips

  • %H 完整哈希,%h 短哈希,%s 提交主题,%an 作者名,%ad 作者日期,%d 装饰信息。
  • git log --follow file.js 可以跟踪文件重命名后的历史。
  • git log main..feature 显示 feature 有但 main 没有的提交,常用于查看分支待合并内容。
  • git reflog 可以查看所有操作历史,包括已删除的分支和提交。
  • 配合 --date=short、--date=relative 等选项可统一日期显示格式。
  • -S 按字符串精确匹配增删,-G 按正则匹配变更内容,两者用途不同。

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Found an error? Report it

Wrong command or description? Open an issue to help us fix it.

Found an error? Report it