3

The tag is exist:

$ git tag
v4.0.0-alpha

but when use describe:

$ git describe --tags
fatal: No tags can describe 'b42e62743a298e1dff2a686fde01319e9a75b65a'.
Try --always, or create some tags.

I did missing something. But what ? How to properly get latest tag of repo ?

egig
  • 4,370
  • 5
  • 29
  • 50
  • Okay, the v4.0.0-alpha tag exists, but is it reachable from HEAD? If that's not immediately obvious you can use http://stackoverflow.com/questions/3005392/how-can-i-tell-if-one-commit-is-a-descendant-of-another-commit to have Git check this for you. – Magnus Bäck May 13 '15 at 05:45
  • 1
    Is it a simple/lightweight tag or is it an annotated tag? By default, `git describe` will only consider annotated tags. You need the `--tags` option to include them. – knittl May 13 '15 at 09:17

1 Answers1

2

You can use

git for-each-ref --count=1 --sort='-*authordate' --format '%(refname:short)' refs/tags

which will show you the latest tag in the repository.

If you use

git describe --abbrev=0 --tags

you will only get the latest tag that is contained in the current HEAD's history.

Sometimes tags are not contained in the history of a branch. E.g. it looks like this:

              master (somelib-1.1-SNAPSHOT)
              |
              V
o----o----o---o
      \
       o
       ^
       |
       somelib-1.0

The reason might be a svn to git migration or maybe some release tools do this.

René Link
  • 48,224
  • 13
  • 108
  • 140
  • tail -n1 only outputs the last line. Run the command without `| tail -n1` and just take a look at the last line. – René Link May 13 '15 at 08:33
  • Do you mean `tail -n1` ? ok, but it's not return latest created tag, I need the newest tag sir, please help :) – egig May 13 '15 at 09:06
  • @egig ohh sorry. I updated my answer to use `tail -n1`. But why isn't it your last tag? `for-each-ref`is applied for all `ref/tags`. Thus the for each loop iterates through all tags. And they are sorted by `taggerdate`. So the last output of `for-each-ref` should be the most recent tag. What do you mean with newest? – René Link May 13 '15 at 09:17
  • @egig I updated my answer to use `-*authordate` and `--count=1`. This should do what you want. – René Link May 13 '15 at 09:25
  • Shows an outdated tag for me (v0.9 instead of v0.31) – andig Nov 23 '20 at 16:13