gitgit-tag

How do I read tagger information from a 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?


Solution

  • This has already been answered a long time ago but still is the top search result even though it's not the best solution anymore, so here it goes:

    Command:

    git for-each-ref refs/tags/$TAG --shell --format='
    TAG=%(refname)
    TYPE=%(objecttype)
    COMMIT=%(objectname)
    TAGGER=%(tagger)
    EMAIL=%(taggeremail)
    DATE=%(taggerdate)
    CONTENTS=%(contents)
    '
    

    --shell does the quoting for Shell scripts. There is also --perl, --python and --tcl. If you don't want to write whole format as a command line option, you can also put it in a file.txt and do this:

    git for-each-ref refs/tags/<tag> --shell --format="$(cat file.txt)"
    

    Output:

    TAG='refs/tags/4.1.0-RC1'
    TYPE='tag'
    COMMIT='973cc103f942330550866588177fe53ea5765970'
    TAGGER='ml_'
    EMAIL='<ml@example.org>'
    DATE='Fri Sep 16 14:14:50 2016 +0200'
    CONTENTS='Release 3:
    * INSTALL.md added.
    * GIT.md modified.
    '
    

    More information here: https://git-scm.com/docs/git-for-each-ref