使用 git log
命令查看提交記錄時,默認打印commit hash值、作者、提交日期、和提交信息。如果想要查看更多內容,可以提供不同的參數來指定查看的信息。具體實例說明如下。
在git log中顯示committer信息
git log
命令默認顯示的裏面只有author,沒有committer,類似於下面的信息:
$ git log
commit b932a847f5xxxxx
Author: John <[email protected]>
Date: Mon Oct 21 16:18:09 2019 +0800
hello release
如果要顯示committer的信息,可以使用 --pretty=full
選項。例如下面顯示的信息:
$ git log --pretty=full
commit b932a847f5xxxxx
Author: John <[email protected]>
Commit: John <[email protected]>
hello release
查看 man git-log 對 --pretty 選項說明如下:
--pretty[=<format>], --format=<format>
Pretty-print the contents of the commit logs in a given format, where <format> can be one of oneline, short, medium, full, fuller, email, raw and format:<string>.
默認的 medium 格式樣式如下:
medium
commit <sha1>
Author: <author>
Date: <author date>
<title line>
<full commit message>
可以顯示 committer 信息的 full 格式樣式如下:
full
commit <sha1>
Author: <author>
Commit: <committer>
<title line>
<full commit message>
這裏的 author 和 committer 的區別是,author 是進行這個修改的人,而 committer 是把這個修改提交到git倉庫的人。
一般來說,我們自己修改代碼,然後執行 git commit,那麼既是 author,又是 committer。
如果別人用 git format-patch 生成 git patch,在patch文件裏面會包含修改者的名稱和郵箱信息。例如:
From 033abaaecdxxxx Mon Sep 17 00:00:00 2001
From: Jobs <[email protected]>
Date: Mon, 21 Oct 2019 16:18:09 +0800
Subject: [PATCH] hello release
我們拿到這個patch文件,用 git am 命令把patch合入本地倉庫,那麼 author 是這個patch文件的修改者 Jobs,而 committer 是我們自己。
只查看某個人的提交歷史
使用 git log --author=<pattern>
命令來查看某個作者的提交歷史。
使用 git log --committer=<pattern>
命令來查看某個提交者的提交歷史。
查看 man git-log 對這兩個選項的說明如下:
--author=<pattern>, --committer=<pattern>
Limit the commits output to ones with author/committer header lines that match the specified pattern (regular expression). With more than one --author=<pattern>, commits whose author matches any of the given patterns are chosen (similarly for multiple --committer=<pattern>).
即,所給的 pattern 參數可以用正則表達式來匹配特定模式。舉例如下:
使用 git log --author=John
查看 John 的上庫信息,如果有多個人名都帶有 John,會匹配到多個人的提交歷史。
使用 git log [email protected]
來查看 [email protected]
這個郵箱的提交歷史。
使用 git log [email protected]
來查看 @xxxx.com
這個郵箱後綴的提交歷史。