【问题标题】:git log of a single revision单个修订的 git 日志
【发布时间】:2011-05-04 04:27:30
【问题描述】:

我有一个提交 c。我想获得那个确切的提交 c + 元信息的变更集,而不是其他的。有没有比git log -p c^..c 更简单的方法来做到这一点?

【问题讨论】:

    标签: git git-log


    【解决方案1】:

    git log -p c -1 就是这样做的。

    【讨论】:

    • -1 有什么作用?它记录在哪里?
    • @alex:“-1”将显示的条目数限制为给定的数字,它是-n 1--max-number=1 的简写,是documented here
    【解决方案2】:

    你可以使用show:

    git show commit_id
    

    【讨论】:

    • 而 git show 默认为 HEAD 作为 commit_id,因此 git show 本身会显示您当前分支的最近一次提交。
    【解决方案3】:

    Michal Trybus 的回答最简单。但是,如果您不希望输出中的差异,您可以随时执行以下操作:

    git log -1 -U c
    

    这将为您提供提交日志,然后您将完全控制所有 git 日志记录选项以实现自动化目的。在您的实例中,您说您想要更改集。最易读的方法是:

    git log --name-status --diff-filter="[A|C|D|M|R|T]" -1 -U c
    

    或者,如果您使用的 git 版本高于 1.8.X,则为:

    git log --name-status --diff-filter="ACDMRT" -1 -U c
    

    这会给你类似的结果:

    commit {c}
    Author: zedoo <zedoo@stackoverflow.com>
    Date: Thu Aug 2 {time-stamp}
    
       {short description}
    D    zedoo/foo.py
    A    zedoo/bar.py
    

    当然,您可以过滤掉您认为合适的任何事件,并通过传统的 git-log 命令格式化返回,这些命令有据可查 here

    【讨论】:

    • 如果您不想要差异,请执行git show --name-only &lt;sha1&gt;
    • 如果你不想要差异,请使用git show -s &lt;commit&gt;
    • -1 是做什么的?它记录在哪里?
    • @alex 查看“提交限制”部分下git help log 的输出。或者查看git-scm.com/book/en/v2/…-&lt;number&gt; 限制输出的提交次数。
    • 如果您不希望差异但文件列表已更改,另一种方法git show --stat &lt;commit&gt;
    【解决方案4】:

    您可以使用提交的描述来过滤更改:

    git log --grep='part_of_description' -p
    

    git log --grep='part_of_description' 选择包含“part_of_description”的提交,-p 显示每个提交的变更集

    【讨论】:

      猜你喜欢
      • 2011-01-16
      • 1970-01-01
      • 2016-08-23
      • 2017-09-16
      • 2013-09-01
      • 2013-01-15
      • 2014-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多