Git:查找所有标签,可从提交访问

Kon*_*yak 5 git git-tag

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

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

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

Cod*_*ard 5

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

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:]]*##'
Run Code Online (Sandbox Code Playgroud)

该脚本只是一个 1 长的行,分解为适合发布窗口。

解释:
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.
Run Code Online (Sandbox Code Playgroud)