Git log 命令

更新时间: 2019-07-13 17:17

git-log - Show commit logs

语法

git log [<options>] [<revision range>] [[--] <path>...]

参数

--follow
    Continue listing the history of a file beyond renames (works only for a single file).

--no-decorate, --decorate[=short|full|auto|no]
    Print out the ref names of any commits that are shown. If short is specified, the ref name prefixes refs/heads/, refs/tags/ and
    refs/remotes/ will not be printed. If full is specified, the full ref name (including prefix) will be printed. If auto is
    specified, then if the output is going to a terminal, the ref names are shown as if short were given, otherwise no ref names are
    shown. The default option is short.

--source
    Print out the ref name given on the command line by which each commit was reached.

--use-mailmap
    Use mailmap file to map author and committer names and email addresses to canonical real names and email addresses. See git-
    shortlog(1).

--full-diff
    Without this flag, git log -p <path>...  shows commits that touch the specified paths, and diffs about the same specified paths.
    With this, the full diff is shown for commits that touch the specified paths; this means that "<path>..." limits only commits, and
    doesn't limit diff for those commits.

    Note that this affects all diff-based output types, e.g. those produced by --stat, etc.

--log-size
    Include a line "log size <number>" in the output for each commit, where <number> is the length of that commit's message in bytes.
    Intended to speed up tools that read log messages from git log output by allowing them to allocate space in advance.

-L <start>,<end>:<file>, -L :<funcname>:<file>
    Trace the evolution of the line range given by "<start>,<end>" (or the function name regex <funcname>) within the <file>. You may
    not give any pathspec limiters. This is currently limited to a walk starting from a single revision, i.e., you may only give zero
    or one positive revision arguments. You can specify this option more than once.

    <start> and <end> can take one of these forms:

    o   number

        If <start> or <end> is a number, it specifies an absolute line number (lines count from 1).

    o   /regex/

        This form will use the first line matching the given POSIX regex. If <start> is a regex, it will search from the end of the
        previous -L range, if any, otherwise from the start of file. If <start> is "^/regex/", it will search from the start of file.
        If <end> is a regex, it will search starting at the line given by <start>.

    o   +offset or -offset

        This is only valid for <end> and will specify a number of lines before or after the line given by <start>.

    If ":<funcname>" is given in place of <start> and <end>, it is a regular expression that denotes the range from the first funcname
    line that matches <funcname>, up to the next funcname line. ":<funcname>" searches from the end of the previous -L range, if any,
    otherwise from the start of file. "^:<funcname>" searches from the start of file.

<revision range>
    Show only commits in the specified revision range. When no <revision range> is specified, it defaults to HEAD (i.e. the whole
    history leading to the current commit).  origin..HEAD specifies all the commits reachable from the current commit (i.e.  HEAD), but
    not from origin. For a complete list of ways to spell <revision range>, see the Specifying Ranges section of gitrevisions(7).

[--] <path>...
    Show only commits that are enough to explain how the files that match the specified paths came to be. See History Simplification
    below for details and other simplification modes.

    Paths may need to be prefixed with ``-- '' to separate them from options or the revision range, when confusion arises.

使用示例

# 显示当前分支的版本历史
$ git log

# 显示commit历史,以及每次commit发生变更的文件
$ git log --stat

# 搜索提交历史,根据关键词
$ git log -S [keyword]

# 显示某个commit之后的所有变动,每个commit占据一行
$ git log [tag] HEAD --pretty=format:%s

# 显示某个commit之后的所有变动,其"提交说明"必须符合搜索条件
$ git log [tag] HEAD --grep feature

# 显示某个文件的版本历史,包括文件改名
$ git log --follow [file]
$ git whatchanged [file]

# 显示指定文件相关的每一次diff
$ git log -p [file]

# 显示过去5次提交
$ git log -5 --pretty --oneline

查看更多 git log 命令的使用方法,可以使用命令:

git help log
像计算机科学家一样思考Python (第2版)

像计算机科学家一样思考Python (第2版)

[美] 艾伦 B. 唐尼 / 赵普明 / 人民邮电出版社 / 2016-7 / 49.00

本书以培养读者以计算机科学家一样的思维方式来理解Python语言编程。贯穿全书的主体是如何思考、设计、开发的方法,而具体的编程语言,只是提供了一个具体场景方便介绍的媒介。 全书共21章,详细介绍Python语言编程的方方面面。本书从基本的编程概念开始讲起,包括语言的语法和语义,而且每个编程概念都有清晰的定义,引领读者循序渐进地学习变量、表达式、语句、函数和数据结构。书中还探讨了如何处理文件和......一起来看看 《像计算机科学家一样思考Python (第2版)》 这本书的介绍吧!

Base64 编码/解码

Base64 编码/解码

Base64 编码/解码

MD5 加密

MD5 加密

MD5 加密工具

XML、JSON 在线转换

XML、JSON 在线转换

在线XML、JSON转换工具