代码之家  ›  专栏  ›  技术社区  ›  Almad

如何在Git中显示单次提交的元数据?

git
  •  37
  • Almad  · 技术社区  · 16 年前

    我想解析Git存储库中的元信息。我想为提交获取单个信息,如

    git log --pretty=format:%an HEAD^..HEAD
    

    问题是,这对于存储库中的第一次提交不起作用。

    git show --pretty=format:%an HEAD^..HEAD
    

    也接近我想要的,只是我对解析实际的差异不感兴趣。

    您知道如何使Git日志在第一次提交时工作,或者如何禁止Git Show显示提交内容吗?

    或者,有没有更好的方法来检索给定提交的元数据?

    3 回复  |  直到 7 年前
        1
  •  57
  •   CB Bailey    16 年前

    提供要显示的安静选项以抑制差异。

    git show --quiet HEAD
    

    例如,作者姓名:

    git show --quiet --pretty=format:%an
    
        2
  •  5
  •   koppor    7 年前
    git --no-pager show -s --format='%an <%ae>' COMMIT
    

    (取自 quora.com )

    • --no-pager supresses the pager
    • -s 抑制差异输出
    • %an 是作者姓名
    • %ae 是作者的电子邮件吗
        3
  •  0
  •   Ciro Santilli OurBigBook.com    8 年前

    git log -n 1 --format='%an'

    -n 1 将日志限制为单个提交。

    git show --quiet 尽管我更喜欢它,因为它被记录在 man git-log 虽然 --quiet 未记录在 man git-show 从2.17开始。

    另外,请注意,你可以用简短的 --安静 :

    git show -q --format='%an'