【问题标题】:Git: find all tags, reachable from a commitGit:查找所有标签,可从提交中访问
【发布时间】:2016-01-21 10:14:18
【问题描述】:

如何列出所有标签,可以从给定的提交访问?

对于所有分支,它是git branch --all --merged <commit>。 对于最近的标签,它是git describe

手册页 git-tag 建议 git tag -l --contains <commit> *,但此命令未显示任何我知道可以访问的标签。

【问题讨论】:

标签: git git-tag


【解决方案1】:

手册页 git-tag 建议使用 git tag -l --contains *,但是这个命令没有显示任何我知道可以访问的标签。

git tag --contains 用于反向搜索。它显示包含给定提交的所有标签。 (这与git branch --contains 的行为相同。)

【讨论】:

    【解决方案2】:

    使用此脚本打印出给定分支中的所有标签

    git log --decorate=full --simplify-by-decoration --pretty=oneline HEAD | \
    sed -r -e 's#^[^\(]*\(([^\)]*)\).*$#\1#' \
    -e 's#,#\n#g' | \
    grep 'tag:' | \
    sed -r -e 's#[[:space:]]*tag:[[:space:]]*##'
    

    脚本只是一长行被分解以适应帖子窗口。

    解释:
    git log 
    
    // Print out the full ref name 
    --decorate=full 
    
    // Select all the commits that are referred by some branch or tag
    // 
    // Basically its the data you are looking for
    //
    --simplify-by-decoration
    
    // print each commit as single line
    --pretty=oneline
    
    // start from the current commit
    HEAD
    
    // The rest of the script are unix command to print the results in a nice   
    // way, extracting the tag from the output line generated by the 
    // --decorate=full flag.
    

    【讨论】:

    • 太好了,这行得通!我仍然想知道为什么git tag -l --contains 不按照它所说的去做......
    • 酷。 :-) 很高兴为您提供帮助
    猜你喜欢
    • 1970-01-01
    • 2011-08-20
    • 2021-06-28
    • 2017-05-14
    • 2015-11-12
    • 2019-01-23
    • 1970-01-01
    • 2015-12-06
    • 2011-05-31
    相关资源
    最近更新 更多