Carson Cole
Carson Cole

Reputation: 4451

Get current GIT tag from within Rails app?

How can I get the most recent GIT tag from within a Rails app? The tag is my release version and I'd like to show in my app.

I know that this will give me the most recent commit:

git rev-parse --short HEAD

Upvotes: 0

Views: 696

Answers (1)

max
max

Reputation: 102001

tag = `git describe`.chomp

The command finds the most recent tag that is reachable from a commit. If the tag points to the commit, then only the tag is shown. Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit. The result is a "human-readable" object name which can also be used to identify the commit to other git commands.

https://git-scm.com/docs/git-describe

You can suppress the suffix with:

tag = `git describe --abbrev=0`.chomp

Upvotes: 1

Related Questions