使用 git log 命令查看提交记录时,默认打印commit hash值、作者、提交日期、和提交信息。如果想要查看更多内容,可以提供不同的参数来指定查看的信息。具体实例说明如下。
在git log中显示committer信息
git log 命令默认显示的里面只有author,没有committer,类似于下面的信息:
$ git log commit b932a847f564c441d68fe954b19b2b275fd1e38d Author: JohnDate: Mon Oct 21 16:18:09 2019 +0800 hello release
如果要显示committer的信息,可以使用 --pretty=full 选项。例如下面显示的信息:
$ git log --pretty=full commit b932a847f564c441d68fe954b19b2b275fd1e38d Author: JohnCommit: John hello release
查看 man git-log 对 --pretty 选项说明如下:
--pretty[=
], --format= Pretty-print the contents of the commit logs in a given format, where
can be one of oneline, short, medium, full, fuller, email, raw and format: .
默认的 medium 格式样式如下:
medium commitAuthor: Date:
可以显示 committer 信息的 full 格式样式如下:
full commitAuthor: Commit:
这里的 author 和 committer 的区别是,author 是进行这个修改的人,而 committer 是把这个修改提交到git仓库的人。
一般来说,我们自己修改代码,然后执行 git commit,那么既是 author,又是 committer。
如果别人用 git format-patch 生成 git patch,在patch文件里面会包含修改者的名称和邮箱信息。例如:
From 033abaaecd9a3133cfcc028726aa37ebdbe6bff4 Mon Sep 17 00:00:00 2001 From: JobsDate: Mon, 21 Oct 2019 16:18:09 +0800 Subject: [PATCH] hello release
我们拿到这个patch文件,用 git am 命令把patch合入本地仓库,那么 author 是这个patch文件的修改者 Jobs,而 committer 是我们自己。
只查看某个人的提交历史
使用 git log --author=
使用 git log --committer=
查看 man git-log 对这两个选项的说明如下:
--author=
, --committer= Limit the commits output to ones with author/committer header lines that match the specified pattern (regular expression). With more than one --author=
, commits whose author matches any of the given patterns are chosen (similarly for multiple --committer= ).
即,所给的 pattern 参数可以用正则表达式来匹配特定模式。举例如下:
使用 git log --author=John 查看 John 的上库信息,如果有多个人名都带有 John,会匹配到多个人的提交历史。
使用 git log --author=john@xxxx.com 来查看 john@xxxx.com 这个邮箱的提交历史。
使用 git log --author=@xxxx.com 来查看 @xxxx.com 这个邮箱后缀的提交历史。