Git 中如何只查看某个用户的提交记录?
Git 查看某人提交:git log --author="名字" 按作者过滤,支持模糊匹配;配合 --oneline、--stat、--since 进一步筛选。本文介绍常用组合。
用 --author 参数:git log --author="John"。名字支持模糊匹配(正则),配合 --oneline、--stat、--since 可以组合出各种视角。
基本用法
# 按作者名过滤
git log --author="John Doe"
# 按邮箱过滤(更精确,同名用户可区分)
git log --author="john@example.com"
常用组合
# 简洁单行显示
git log --author="John" --oneline
# 带每次提交的文件变更统计
git log --author="John" --stat
# 只看最近两周
git log --author="John" --since="2 weeks ago"
# 统计提交次数
git log --author="John" --oneline | wc -l
统计所有人的提交数
git shortlog -sn
按提交数从高到低列出所有贡献者,快速了解每个人的提交量。
常见问题(FAQ)
Q:--author 区分大小写吗?
A:默认是正则匹配,区分大小写;加 -i 忽略大小写:git log -i --author="john"。
Q:多个作者怎么查?
A:git log --author="John\|Jane"(正则 OR),或多次 --author 参数(Git 2.13+ 支持多个)。
Q:author 和 committer 有什么区别?
A:author 是写代码的人,committer 是执行提交的人(rebase/cherry-pick 时两者会不同)。--author 按 author 过滤,--committer 按 committer 过滤。