Reputation: 4451
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
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.
You can suppress the suffix with:
tag = `git describe --abbrev=0`.chomp
Upvotes: 1