查看历史(git log)
约 444 字大约 1 分钟
布欧-Lewyon
2026-05-15
首页 › Git › 本地仓库操作(在新窗口打开) › 查看历史(git log)
git log 基本用法
# 完整日志
git log
# 一行模式
git log --oneline
# 图形化展示(分支拓扑)
git log --oneline --graph --all --decorate输出格式
# 完整 hash + 作者 + 日期
git log --format=fuller
# 自定义格式
git log --pretty=format:"%h - %an, %ar : %s"
# %h 简短 hash
# %an 作者名
# %ar 相对日期(3 days ago)
# %s 提交信息
# %d 引用名(分支/标签)过滤日志
# 最近 N 条
git log -5
git log -3 --oneline
# 按日期
git log --since="2026-01-01"
git log --until="2026-03-01"
git log --since="2 weeks ago"
# 按作者
git log --author="zhangsan"
# 按提交信息
git log --grep="fix"
git log --grep="feat" --grep="fix" --all-match
# 按文件
git log -- README.md
# 按范围
git log main..feature # feature 有但 main 没有的提交
git log feature --not main # 同上git show
查看某次提交的详细信息:
# 查看最近一次提交
git show
# 查看特定提交
git show a1b2c3d
# 只看提交信息
git show -s a1b2c3d
# 查看某次提交的某个文件
git show a1b2c3d -- README.md
# 统计变更
git show --statgit shortlog
按作者汇总提交:
# 按作者分组显示
git shortlog
# 只显示提交数量
git shortlog -sn
# 按邮箱合并不同名字
git shortlog -sn -e常用 log 别名
git config --global alias.lg "log --oneline --graph --all --decorate"
git config --global alias.la "log --oneline --graph --all --decorate --simplify-by-decoration"
# 使用
git lg
git la小结
git log --oneline --graph --all --decorate是最常用的历史查看组合。- 按
--author、--since、--grep过滤日志。 git show <commit>查看单次提交详情。git shortlog -sn按作者汇总提交数。- 配置
git lg别名提高效率。
上一节:查看状态与变更 下一节:文件操作与 .gitignore
