git log --author 用于按作者名或邮箱筛选提交,匹配 git config user.name 值;推荐用邮箱过滤更准确;需加 --all 查所有分支;注意 author 与 committer 区别。

git log --author 查看指定开发者提交
直接用 git log --author="张三" 就能筛出名字含“张三”的提交。注意这里匹配的是 git config user.name 设置的值,不是邮箱,也不是 GitHub 用户名。如果作者名带空格或特殊字符,建议加双引号;正则匹配需加 --regexp-ignore-case 或用 -i,比如 git log --author="(?i)zhang.*san"。
按邮箱过滤更准确
很多人配置的 user.name 不规范(比如写成“zs”或“ZS”),但邮箱通常唯一且稳定。用 git log --author="zhangsan@example.com" 更可靠。如果记不清完整邮箱,可用通配:git log --author="zhangsan@.*"(需启用正则,加 -E 参数:git log -E --author="zhangsan@.*")。
配合其他选项提升可读性与实用性
单纯 git log --author 输出冗长,建议组合常用参数:
-
git log --author="zhangsan@example.com" --oneline --graph --all:紧凑格式 + 分支图 + 所有分支 -
git log --author="zhangsan@example.com" --since="2024-01-01" --until="2024-06-30":限定时间范围 -
git log --author="zhangsan@example.com" --pretty=format:"%h %ad %s" --date=short:自定义输出字段和日期格式
注意:--all 是关键——默认只查当前分支,漏掉其他分支的提交是常见疏忽。
区分 author 和 committer,避免误判
Git 中 author 是代码实际编写者,committer 是执行 git commit 的人。二者不同时(比如用 git commit --amend 或通过 CI 提交),--author 仍查原始作者,而 --committer 才查操作者。若想查“谁合入了某人的代码”,得换用 --committer。这点在 Code Review 后由他人推送的场景里特别容易搞混。
真正麻烦的是混合了别名、大小写不一致、多邮箱、以及提交历史被 rebase 过的情况——这时候单靠 --author 不够,得结合 git shortlog -sne 先确认真实作者标识,再针对性筛选。


















