1

I have a work flow where i want to use git tags to push releases though my pipeline.

git init touch readme.md git add . git commit -m "com1" git tag -a 1.0.0-rc.1 -m "t1" touch xxx git add . git commit -m "com2" git tag -a 1.0.0-alpha1 -m "t2" git tag -a 1.0.0-rc1 -m "t2" git tag -a 1.0.0 -m "r1" 

My log looks like:

commit 132fa7712234e0ea0ee72b55123d9fbfd7dbe75a (HEAD -> master, tag: 1.0.0-alpha1, tag: 1.0.0-rc1, tag: 1.0.0) Author: Ryan Date: Mon Nov 26 11:08:21 2018 +0000 com2 commit 97c10b1c203bc34f1234ba38e214c9f72cc4a03a (tag: 1.0.0-rc.1) Author: Ryan Date: Mon Nov 26 11:07:43 2018 +0000 com1 

How can I ensure that only the most recent tag is returned?

6
  • What is your definition of "most recent tag"? Commented Nov 26, 2018 at 12:05
  • In this case, 1.0.0 would be the most recent as it was committed last. Basically I want the tag that was added last on head Commented Nov 26, 2018 at 12:55
  • AFAIU the question is about git log decorations: (HEAD -> master, tag: 1.0.0-rc.2, tag: 1.0.0). @Ryan wants to see (HEAD -> master, tag: 1.0.0). I don't think it's possible with git log. Commented Nov 26, 2018 at 12:59
  • I use git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null but it is returning the alpha tag which is the 1st one added in that last commit. Commented Nov 26, 2018 at 13:02
  • @phd Wouldn't --decorate=full do the job for git log output? Commented Nov 26, 2018 at 13:10

1 Answer 1

1
git describe <commit ID> 

does the job.

It returns the most recent tag reachable by this commit, then if the tag is not on the commit itself, appends a description of said commit (# of commits "away" + tagged commit ID)

See the documentation for the options and details.

Alternatively, if as comments suggest you seek to make this info appear in the output of git log, try the option --decorate=full

Sign up to request clarification or add additional context in comments.

1 Comment

I think this will work well enough, I only didnt consider it because it will return <lastTag>-#-g####### even if no tag is applied to that commit (when one has been used in a prior commit). I was ideally looking for: if tagged -> showLatestTag else git describe

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.