Git 日志查看速查表
Git log 是查看提交历史的命令,整理常用格式和过滤选项,快速定位代码变更。
返回 版本控制格式化输出 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 可以查看所有操作历史,包括已删除的分支和提交。