Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: find all tags, reachable from a commit

Tags:

git

git-tag

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.

like image 903
Konstantin Shemyak Avatar asked Oct 22 '15 07:10

Konstantin Shemyak


People also ask

How do I see tags on a commit?

In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.

How do I see all tags on GitHub?

Viewing tags On GitHub.com, navigate to the main page of the repository. To the right of the list of files, click Releases. At the top of the Releases page, click Tags.

How will you list your tags in git?

Listing the available tags in Git is straightforward. Just type git tag (with optional -l or --list ). You can also search for tags that match a particular pattern. The command finds the most recent tag that is reachable from a commit.

Do git tags get merged?

Tags are not merged, commits (tagged or not) are.


1 Answers

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.
like image 123
CodeWizard Avatar answered Oct 14 '22 20:10

CodeWizard