【问题标题】:Can git list the tags that occur between two particular commits?git 可以列出两个特定提交之间发生的标签吗?
【发布时间】:2013-05-09 00:57:33
【问题描述】:

有没有办法让 git 列出两次提交之间添加的所有标签?也就是说,只显示出现在 A 点和 B 点之间的标签。

【问题讨论】:

    标签: git tags commit


    【解决方案1】:

    您可以将git log 命令与这些选项一起使用:

    git log tagA...tagB --decorate --simplify-by-decoration
    

    --decorate 显示提交旁边的标记名称,--simplify-by-decoration 仅显示已标记的提交。

    【讨论】:

    • 您也可以使用提交校验和,这可能是该问题的更合适的答案:git log commitA...commitB --decorate --simplify-by-decoration
    • git log --decorate --simplify-by-decoration tagA...tagB...不要相信你在互联网上读到的一切。
    【解决方案2】:

    如果您想要commit1commit2之间的标签名称列表(按时间倒序排列),您可以将git logxargsgit tag --points-at结合起来:

    git log commit1..commit2 --simplify-by-decoration --format=format:%h | xargs -L1 git tag --points-at
    

    【讨论】:

      【解决方案3】:

      此命令有效地列出了提交commit1commit2 之间的所有标签(不包括commit1 本身)。

      git log --simplify-by-decoration --pretty=format:%D commit1..commit2 | \
          grep -o 'tag: [^,)]\+' | sed 's/^tag: //'
      

      git log ... 命令列出了引用指定范围内每个提交的分支和标签。随后的命令只解析出标签。

      【讨论】:

        猜你喜欢
        • 2018-05-26
        • 2011-08-17
        • 1970-01-01
        • 2021-01-19
        • 2013-09-11
        • 2019-12-15
        • 2011-05-31
        • 1970-01-01
        相关资源
        最近更新 更多