Git 日志查看速查表

Git log 是查看提交历史的命令,整理常用格式和过滤选项,快速定位代码变更。

版本控制·共 14 条命令·最后更新 2026-07-19
返回 版本控制

格式化输出 5

git log --oneline
单行显示提交
git log --pretty=format:"%h %s"
自定义格式:%h 短哈希 %s 主题
git log --graph --oneline --all
图形化显示所有分支
git log --stat
显示文件变更统计
git log -p
显示每次提交的差异

过滤条件 5

git log --author="John"
按作者过滤
git log --since="2024-01-01"
按时间过滤
git log --grep="fix"
按提交信息过滤
git log -- file.js
查看指定文件的历史
git log -S "function_name"
搜索代码变更

统计与分析 4

git log --shortstat
简要统计:文件数、插入、删除
git log --numstat
每个文件的插入删除统计
git shortlog -sn
按作者统计提交数
git log --cherry-pick --right-only main...feature
查看分支独有提交

💡 提示

  • %H 完整哈希,%h 短哈希,%s 提交主题,%an 作者名,%ad 作者日期。
  • git log --follow file.js 可以跟踪文件重命名后的历史。
  • git log main..feature 显示 feature 有但 main 没有的提交。
  • git reflog 可以查看所有操作历史,包括已删除的分支和提交。