Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read tagger information from a GIT tag?

Tags:

git

git-tag

So far I have:

git rev-parse <tagname> | xargs git cat-file -p 

but this isn't the easiest thing to parse. I was hoping for something similar to git-log's --pretty option so I could grab just the info I need.

Any ideas?

like image 431
quornian Avatar asked Nov 15 '10 15:11

quornian


People also ask

How do you fetch a tag?

To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options. Let's say for example that you have a tag named “v1. 0” that you want to check out in a branch named “release”. Using this command, you have successfully checked out the “v1.

Which command is used to list the available 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.

How can I see my repository tags?

View tags for a repository (console)In Repositories, choose the name of the repository where you want to view tags. In the navigation pane, choose Settings. Choose Repository tags.


1 Answers

A more direct way of getting the same info is:

git cat-file tag <tagname> 

This uses a single command and avoids the pipe.

I used this in a bash script as follows:

if git rev-parse $TAG^{tag} -- &>/dev/null then     # Annotated tag     COMMIT=$(git rev-parse $TAG^{commit})     TAGGER=($(git cat-file tag $TAG | grep '^tagger'))     N=${#TAGGER} # Number of fields     DATE=${TAGGER[@]:$N-2:2} # Last two fields     AUTHOR=${TAGGER[@]:1:$N-3} # Everything but the first and last two     MESSAGE=$(git cat-file tag $TAG | tail -n+6) elif git rev-parse refs/tags/$TAG -- &>/dev/null then     # Lightweight tag - just a commit, basically     COMMIT=$(git rev-parse $TAG^{commit}) else     echo "$TAG: not a tag" >&2 fi 
like image 82
Neil Mayhew Avatar answered Sep 20 '22 18:09

Neil Mayhew