Finding git tags with describe

Published at
Updated at
Reading time
2 min

This post is part of my Today I learned series in which I share all my learnings regarding web development.

In one of our Slack channels at Contentful I recently read a few messages by Anthony who's one of our infrastructure developers. He was mentioning the git command describe which I haven't used before.

From the official documentation this is what it does:

Describe a commit using the most recent tag reachable from it

Okay, but what does that mean? I opened my terminal and started playing around with it in one of my projects.

~/Projects/forrest | ๐Ÿบ ๐Ÿ•Š ๐Ÿฑ    master (โ•ฏยฐโ–กยฐ)โ•ฏ
> git describe

As the last commit was tagged there is no surprise by executing it in there. So I checked out a previous commit and ran it again.

~/Projects/forrest | ๐Ÿณ ๐ŸŸ ๐Ÿ˜    46b7ebb ใƒพ(โŒโ– _โ– )ใƒŽ
> git describe

Interesting. v1.0.0-epsilon is the next recent tag. Cool! The tag name is then followed by the number of commits on top of the tag and the commit hash of the current commit prefixed with -g (this is used to describe that we're dealing with git here).

|              ||  |
 \___     ____/  \  \----------- commit hash
      most        \
     recent        commits
      tag            on

Reading the documenation I also found out that you can get all the commits between two other commits by doing git log hash1..hash2. Another thing I didn't know! ๐ŸŽ‰

~/Projects/forrest | ๐Ÿ˜“ ๐Ÿ ๐Ÿœ    master ใƒพ(โŒโ– _โ– )ใƒŽ
> git log 3bc8cdf..8973bae

commit 8973bae7ec443f0a683ddd239cf3a8e9015877cb
Author: Stefan Judis 
Date:   Thu Aug 18 00:47:43 2016 +0200

    keep session history clean by space prefix - fix #68 (#73)

commit fc7ac34f9c59343c58e6a954e0add30bff6a3d8a
Author: Greenkeeper 
Date:   Thu Aug 18 00:24:23 2016 +0200

    chore(package): update dependencies (#61)

commit fad11bd51d0c13dd7ca09084ddfe9b55fe8a90f1
Author: Stefan Judis 
Date:   Thu Aug 18 00:14:37 2016 +0200

    only build on node v6 - fix #71 (#72)

So, describe has a lot of options to configure the search for tags more granular. You should definitely have a look if you're looking up tags constantly.

And that's it for today. ;)

Related Topics

See null comment.