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.
Back to Version ControlFormatting Output 6
git log --onelineShow commits on a single line
git log -n 10Show only the last 10 commits
git log --pretty=format:"%h %s"Custom format: %h short hash, %s subject
git log --graph --oneline --allGraph all branches
git log --statShow file change statistics
git log -pShow 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.jsShow 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-mergesExclude merge commits
git log --first-parentFollow only the first-parent of the main line
Statistics & Analysis 6
git log --shortstatBrief stats: files, insertions, deletions
git log --numstatPer-file insert/delete stats
git log --dirstatChange proportion by directory
git shortlog -snCount commits by author
git shortlog -sneCount commits by author with email
git log --cherry-pick --right-only main...featureShow commits unique to a branch
Ranges & Diffs 5
git log main..featureCommits in feature but not in main
git log HEAD~3..HEADShow the last 3 commits
git log origin/main..HEADLocal commits not yet pushed
git log --cherry-mark main...featureMark equivalent commits (=) and unique (+)
git log --left-right main...featureMark which side a commit belongs to
File History Tracking 5
git log --follow file.jsFollow history across renames
git log --name-onlyShow changed file names per commit
git log --name-statusShow file names and status (A/M/D)
git log --oneline -- file.jsSingle-line history of a file
git log -p --follow file.jsFull diff across renames
Format Placeholders 10
%HFull commit hash
%hAbbreviated commit hash (--abbrev-commit)
%sSubject (first line)
%anAuthor name
%aeAuthor email
%adAuthor date (use --date=short)
%arAuthor relative date (e.g. "2 days ago")
%dRef (branch/tag) decoration
%bBody message
%cnCommitter name
Useful Aliases & Combos 6
git log --oneline --graph --decorate --allGraph all refs with decorations
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=shortCommon custom log format
git log --since="2 weeks ago" --onelineCommits from the last two weeks
git log --merges --onelineShow only merge commits
git config alias.lg "log --graph --oneline --decorate --all"Set an lg alias, then use git lg
git log --source --onelineShow 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