【问题标题】:Get the commit ID of the last tag in git history获取 git 历史中最后一个标签的提交 ID
【发布时间】:2021-06-15 20:57:35
【问题描述】:

我正在进行未标记的提交。但是提交历史中有标签。因此,以下命令为我提供了历史记录中的最新发布标签

git describe --abbrev=0 --tags

上面输出像1.15.21这样的标签,这很好。
如何获取创建此标签的提交 ID?

【问题讨论】:

    标签: git git-commit


    【解决方案1】:

    您可以使用git rev-parse 获取分支/标签对应的提交

    git rev-parse HEAD
    abc123......
    

    因此您可以使用xargs 管道输出git describe 的输出

    git describe --abbrev=0 --tags | xargs git rev-parse
    def456.....
    

    【讨论】:

    • 你确定xargs git rev-parse 在发布标签处获得提交吗?
    • @TheWaterProgrammer 是的,这是正确的。您可以通过运行 git rev-parse 1.15.21git log -1 1.15.21 并将提交 ID 与通过管道生成的提交 ID 与 xargs 进行比较来说服自己。
    猜你喜欢
    • 1970-01-01
    • 2021-10-13
    • 2014-11-01
    • 2015-03-25
    • 1970-01-01
    • 2017-04-22
    • 2013-06-03
    • 2013-01-23
    • 1970-01-01
    相关资源
    最近更新 更多