【问题标题】:Git commit dateGit 提交日期
【发布时间】:2011-04-18 09:55:30
【问题描述】:

除了为日期字符串解析 git log 之外,还有 Git 原生的方式来报告某个提交的日期吗?

【问题讨论】:

标签: git


【解决方案1】:

显示 命令可能是你想要的。试试

git show -s --format=%ci <commit>

日期字符串的其他格式也可用。检查manual page 详情。

【讨论】:

  • 要获得没有差异的提交,请使用log -1 而不是show
  • 或者在命令中添加'-s':git show -s --format="%ci" &lt;commit&gt;
  • 对于未来的用户:您可以通过%ai查看作者日期
  • 获取unix时间戳:使用 git show -s --format=%ct
  • 如果你想要其他日期格式,你可以使用git show -s --format=%cd --date=short &lt;commit&gt;(例如2016-11-02)或者git show -s --format=%cd --date=short &lt;commit&gt;或者git show -s --format=%cd --date=format:%Y &lt;commit&gt;(这个例子只打印年份)了解详情见this answer
【解决方案2】:

如果您想自己格式化日期(或小时):

git show -s --date=format:'%Y%m%d-%H%M' --format=%cd  <commit id | default is the last commit>

# example output:
20210712-1948

【讨论】:

    【解决方案3】:

    您可以使用git show 命令。

    从 git 存储库中获取最后一次提交日期(Unix 纪元时间戳):

    • 指挥部: git show -s --format=%ct
    • 结果: 1605103148

    注意:您可以访问git-show 文档以获取有关选项的更详细说明。

    【讨论】:

      【解决方案4】:

      如果您在使用 windows cmd 命令和 .bat 时遇到问题 就这样逃避百分比

      git show -s --format=%%ct
      

      % 字符对于命令行参数和 FOR 参数有特殊的含义。 要将百分比视为常规字符,请将其加倍:%%

      Syntax : Escape Characters, Delimiters and Quotes

      【讨论】:

        【解决方案5】:

        如果你喜欢没有时区但本地时区的时间戳

        git log -1 --format=%cd --date=local
        

        这取决于您的位置

        Mon Sep 28 12:07:37 2015
        

        【讨论】:

        • 是否可以一次将它应用于所有提交?
        【解决方案6】:

        如果您只想查看标签的日期,您可以这样做:

        git show -s --format=%ci <mytagname>^{commit}
        

        给出:2013-11-06 13:22:37 +0100

        或者做:

        git show -s --format=%ct <mytagname>^{commit}
        

        给出 UNIX 时间戳:1383740557

        【讨论】:

        • 这似乎给出了标签指向的提交日期,而不是标签本身的日期。
        猜你喜欢
        • 2020-07-29
        • 2022-01-16
        • 2014-06-29
        • 2020-07-06
        • 2015-01-13
        • 2013-12-20
        • 2012-10-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多