Finding git tags with the git describe command
- Published at
- Updated at
- Reading time
Today, in one of our Slack channels at Contentful, I read a few of our infrastructure developers' messages. They talked about how they use the git command
describe to access release version control information. I haven't used this command before and found out more.
git describe documentation describes the command's functionality as follows:
The command finds the most recent tag that is reachable from a commit
Okay, but what does that mean? I opened my terminal and started playing around with it in one of my projects.
$ git describe v1.0.0-zeta
In this repository, the last commit was a tagged release (
v1.0.0-zeta). By default,
describe looks into the past from the repository's
HEAD. If your
HEAD is on a tag, like mine in this case, it shows the last tag without any additional meta information. That's not helpful. 🙈
I checked out a previous commit to see more and ran
git describe again.
$ git describe v1.0.0-epsilon-2-g46b7ebb
In that case, the command output includes more information.
v1.0.0-epsilon is the next reachable tag and the output "encodes" other facts, too. The tag name is followed by the number of commits on top of the tag plus the commit hash of the current commit prefixed with
-g (this is used to describe that we're dealing with git here).
v1.0.0-epsilon-2-g46b7ebb | || | \___ ____/ \ \----------- commit hash most \ of the current commit recent commits tag on top
If you don't want to manually check out a particular commit, you can also pass a commit hash argument to find the next release tag.
$ git describe e85517a284088
describe command has a lot of configurations to the search for tags more granular. You should have a look if you're looking for tagged commits constantly. And that's it for today. ;)
# Additional learning – how to access all commits between two commits
Reading the documention, 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! 🎉
$ git log 3bc8cdf..8973bae commit 8973bae7ec443f0a683ddd239cf3a8e9015877cb Author: Stefan Judis <firstname.lastname@example.org> Date: Thu Aug 18 00:47:43 2016 +0200 keep session history clean by space prefix - fix #68 (#73) commit fc7ac34f9c59343c58e6a954e0add30bff6a3d8a Author: Greenkeeper <email@example.com> Date: Thu Aug 18 00:24:23 2016 +0200 chore(package): update dependencies (#61) https://greenkeeper.io/ commit fad11bd51d0c13dd7ca09084ddfe9b55fe8a90f1 Author: Stefan Judis <firstname.lastname@example.org> Date: Thu Aug 18 00:14:37 2016 +0200 only build on node v6 - fix #71 (#72)