简体   繁体   中英

Git: find all tags, reachable from a commit

How can I list all tags , reachable from a given commit?

For all branches , it is git branch --all --merged <commit> . For most recent tag , it is git describe .

Man page git-tag suggests git tag -l --contains <commit> * , but this command does not show any of the tags which I know are reachable.

use this script to print out all the tags that are in the given branch

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:]]*##'

The script is simply a 1 long line breaked down to fit in the post window.

Explanation:
 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. 

Man page git-tag suggests git tag -l --contains *, but this command does not show any of the tags which I know are reachable.

git tag --contains is for the opposite search. It shows all tags containing the given commit. (This is the same behaviour as git branch --contains .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM