git log 命令用法实例 (2)

使用 git log 命令查看提交记录时,默认打印commit hash值、做者、提交日期、和提交信息。若是想要查看更多内容,能够提供不一样的参数来指定查看的信息。具体实例说明以下。git

在git log中显示committer信息

git log 命令默认显示的里面只有author,没有committer,相似于下面的信息:正则表达式

$ git log
commit b932a847f5xxxxx
Author: John <john@xxxx.com>
Date:   Mon Oct 21 16:18:09 2019 +0800

    hello release
复制代码

若是要显示committer的信息,能够使用 --pretty=full 选项。例以下面显示的信息:express

$ git log --pretty=full
commit b932a847f5xxxxx
Author: John <john@xxxx.com>
Commit: John <john@xxxx.com>

    hello release
复制代码

查看 man git-log 对 --pretty 选项说明以下:bash

--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>.ui

默认的 medium 格式样式以下:spa

medium
        commit <sha1>
        Author: <author>
        Date:   <author date>

        <title line>

        <full commit message>
复制代码

能够显示 committer 信息的 full 格式样式以下:code

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文件里面会包含修改者的名称和邮箱信息。例如:orm

From 033abaaecdxxxx Mon Sep 17 00:00:00 2001
From: Jobs <jobs@xxxx.com>
Date: Mon, 21 Oct 2019 16:18:09 +0800
Subject: [PATCH] hello release
复制代码

咱们拿到这个patch文件,用 git am 命令把patch合入本地仓库,那么 author 是这个patch文件的修改者 Jobs,而 committer 是咱们本身。ip

只查看某我的的提交历史

使用 git log --author=<pattern> 命令来查看某个做者的提交历史。
使用 git log --committer=<pattern> 命令来查看某个提交者的提交历史。
查看 man git-log 对这两个选项的说明以下:ci

--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 --author=john@xxxx.com 来查看 john@xxxx.com 这个邮箱的提交历史。
使用 git log --author=@xxxx.com 来查看 @xxxx.com 这个邮箱后缀的提交历史。

相关文章
相关标签/搜索