Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The vc bundle is a neat little package that extracts information about a git repo for easy insertion into a LaTeX document. It doesn't currently extract information about whether the current commit is tagged and what the tag name is. How would I edit the vc script to do this?

And then how would I edit the vc-git.awk script to add an extra line to the generated vc.tex file? Presumably I want a line that looks like:

print "\\gdef\\GITTag{" Tag "}%"

but I need an earlier line that tells awk what " Tag " means?

This isn't a question about LaTeX, it is about git, awk and bash...

share|improve this question
up vote 1 down vote accepted
git log --decorate -1 [commit]

If commit (HEAD if omitted) has tags, the commit hash will be followed by (tag: name) (and possibly multiple other symbolic references too). You can pick this out more specifically with

git log --pretty=%d
share|improve this answer
This i great, I've added Tag: %d to the vc script linked to above, and copied a line in the awk script that extracts the information to a TeX macro. This gives me a macro that does: (HEAD, tag: v1.01, master) I just need to cut this down to the v1.01 part only... – Seamus Jan 11 '11 at 16:30
/^GITTag:/ {print $4}' prints v1.01, Now I just need to delete that comma! – Seamus Jan 11 '11 at 20:14
print substr($4,1,length($4)-1) works – Seamus Jan 11 '11 at 22:22

You can get what commit tag points to by:

git show -s 'TAG_NAME^{commit}' --format='%H'

Unfortunatly I'm afraid that the only way of checking if commit is tagged it to check all tags.

share|improve this answer
That's the opposite of what I want: I want to know how to know what tag is attached to a given commit... – Seamus Dec 21 '10 at 15:31
I don't think the reverse is possible in other way then going through all tags and checking what commits they point to. – Maciej Piechotka Dec 21 '10 at 15:52

You can get from a commit to a tag name by using name-rev.

git name-rev <commit> --tags

An example:

$ git name-rev fcfeabe --tags
fcfeabe tags/v2.36-beta2

So to get only the tag:

git name-rev fcfeabe --tags | awk '{sub("tags/", ""); print $2}' 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.