【问题标题】:Get latest commit which contains a particular string获取包含特定字符串的最新提交
【发布时间】:2022-01-12 20:13:12
【问题描述】:

我想获取包含字符串的最新提交。 例如

String = TAG_2021_09_0051

我已经尝试过git log --grep "TAG_2021_09_0051",它在输出下方给了我,因为字符串存在于两个提交中。但我想要获取提交 ID 的最新提交。

commit 12345678
Author: none
Date:   Fri Oct 15 21:39:56 2016 +0000

    @: 1234 - TAG_2021_09_0051

commit 45678965
Author: none
Date:   Fri Oct 14 21:39:56 2016 +0000

    @: 1234 - TAG_2021_09_0051

是否有任何方法可以获取包含特定字符串的最新 git 提交,即使该字符串存在于多个提交中?

实际输出应该低于commit

commit 12345678
    Author: none
    Date:   Fri Oct 15 21:39:56 2016 +0000
    
        @: 1234 - TAG_2021_09_0051

【问题讨论】:

    标签: git github git-commit git-log git-rev-list


    【解决方案1】:

    从 git log 文档中你想要-n 选项(https://git-scm.com/docs/git-log):

    git log --grep "TAG_2021_09_0051" -n1
    

    【讨论】:

      猜你喜欢
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 2015-01-20
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 2021-12-31
      • 2021-03-21
      相关资源
      最近更新 更多