# Fw: git describe issue

4 messages from 2019-04-03 to 2019-04-03. Participants: Amiel Elboim, Bryan Turner, Philip Oakley.
Thread: https://gitlist.dev/t/50864

## Amiel Elboim, 2019-04-03 06:47

Subject: Fw: git describe issue
Message-ID: <AM6PR08MB4199B076CB886AE814AFF4528D570@AM6PR08MB4199.eurprd08.prod.outlook.com>
URL: https://gitlist.dev/e/AM6PR08MB4199B076CB886AE814AFF4528D570%40AM6PR08MB4199.eurprd08.prod.outlook.com
In-Reply-To: <AM6PR08MB41993844F57794DDF4B33B8F8D570@AM6PR08MB4199.eurprd08.prod.outlook.com>

```


Hi!

I've found strange behavior with 'git describe' command, look like for me as bug. 

In the case I create 2 tags on same commit and I run 'git describe --tags' I expect to get the latest tag, but always I get the first tag I created on the commit.

Unlike git-describe documentations - "The command finds the most recent tag that is reachable from a commit. "

Simple example -   



amiel@CLINIKALDEV10:~/Xpress$ git tag v1
amiel@CLINIKALDEV10:~/Xpress$ git tag v2
amiel@CLINIKALDEV10:~/Xpress$ git describe --tags
v1
amiel@CLINIKALDEV10:~/Xpress$ gl
* 4f54749 (HEAD -> master, tag: v2, tag: v1, origin/master, origin/HEAD) start point with git



I'll happy to know if is bug or I don't understand something.


Thanks


Amiel  

  


     
```

## Bryan Turner, 2019-04-03 06:59

Subject: Re: Fw: git describe issue
Message-ID: <CAGyf7-HUAoYURDnnp+nq+4EQkysoTE+f_WK8cEVPCHP065rv6A@mail.gmail.com>
URL: https://gitlist.dev/e/CAGyf7-HUAoYURDnnp%2Bnq%2B4EQkysoTE%2Bf_WK8cEVPCHP065rv6A%40mail.gmail.com
In-Reply-To: <AM6PR08MB4199B076CB886AE814AFF4528D570@AM6PR08MB4199.eurprd08.prod.outlook.com>

```
On Tue, Apr 2, 2019 at 11:47 PM Amiel Elboim <amielel@matrix.co.il> wrote:
> Hi!
>
> I've found strange behavior with 'git describe' command, look like for me as bug.
>
> In the case I create 2 tags on same commit and I run 'git describe --tags' I expect to get the latest tag, but always I get the first tag I created on the commit.
>
> Unlike git-describe documentations - "The command finds the most recent tag that is reachable from a commit. "
>
> Simple example -
>
> amiel@CLINIKALDEV10:~/Xpress$ git tag v1
> amiel@CLINIKALDEV10:~/Xpress$ git tag v2
> amiel@CLINIKALDEV10:~/Xpress$ git describe --tags
> v1

With this example, Git has no way to know which tag is "newer".
They're lightweight tags, which means they have no metadata of their
own; they just tag a commit. That means, as far as "age" goes, they're
both the same because their age is drawn from the tagged commit, which
is the same for both. (Since tag names are entirely free-form, I'm not
sure Git makes any effort to try and parse them to "guess" which is
newer; that seems like a Sisyphean task to me.)

If you run this with annotated tags, you get different output (at
least on Git 2.20.1, what I happened to have installed; you never
mentioned your Git version)
incom@Jael MINGW64 /c/Temp/first.git (BARE:master)
$ git tag -a v1
incom@Jael MINGW64 /c/Temp/first.git (BARE:master)
$ git tag -a v2
incom@Jael MINGW64 /c/Temp/first.git (BARE:master)
$ git describe --tags
v2

Hope this helps!
Bryan

```

## Bryan Turner, 2019-04-03 08:11

Subject: Re: Fw: git describe issue
Message-ID: <CAGyf7-GcrWX-TRP89a1SqKu4h74Mbezq0ifHpS305epfmKxJvw@mail.gmail.com>
URL: https://gitlist.dev/e/CAGyf7-GcrWX-TRP89a1SqKu4h74Mbezq0ifHpS305epfmKxJvw%40mail.gmail.com
In-Reply-To: <AM6PR08MB4199EE3834CBF84D28244D9E8D570@AM6PR08MB4199.eurprd08.prod.outlook.com>

```
On Wed, Apr 3, 2019 at 1:00 AM Amiel Elboim <amielel@matrix.co.il> wrote:
>
> Very helpful!  annotated tag is good solution for us.
>
> However fix of this issue is important, because it's confusing when you want to track on your version using git tags.

Lightweight tags have no metadata to allow for ordering, so I'm not
sure there's something to "fix" here. Given the tags have identical
timestamps, Git simply displays the one that's first alphabetically.

Git does have some ability to parse versions and sort them, on newer
versions, but there's no way to activate that via "git describe
--tags", at least as far as I'm aware (and I'm not sure how reliable
it can be, given tag names are essentially free-form text).

You can try Git's version sorting with a command like "git tag
--sort=-v:refname" (The "-" before "v:refname" sorts in descending
order)

incom@Jael MINGW64 /c/Temp/fourth.git (BARE:master)
$ git tag
v1
v2
incom@Jael MINGW64 /c/Temp/fourth.git (BARE:master)
$ git tag --sort=-v:refname
v2
v1

Since you can't enable that for "git describe --tags", though, I'm not
sure it's helpful. (Someone else can correct me if there is a way to
make "git describe" do that.)

Bryan

(Re-added the list on CC)

```

## Philip Oakley, 2019-04-03 09:19

Subject: Re: Fw: git describe issue
Message-ID: <16a9780d-9c3e-673a-4567-f0c4d93f88bc@iee.org>
URL: https://gitlist.dev/e/16a9780d-9c3e-673a-4567-f0c4d93f88bc%40iee.org
In-Reply-To: <CAGyf7-GcrWX-TRP89a1SqKu4h74Mbezq0ifHpS305epfmKxJvw@mail.gmail.com>

```
On 03/04/2019 09:11, Bryan Turner wrote:
> On Wed, Apr 3, 2019 at 1:00 AM Amiel Elboim <amielel@matrix.co.il> wrote:
>> Very helpful!  annotated tag is good solution for us.
>>
>> However fix of this issue is important, because it's confusing when you want to track on your version using git tags.
> Lightweight tags have no metadata to allow for ordering, so I'm not
> sure there's something to "fix" here.
wouldn't the 'fix'  be to the documentation that Amiel quoted to clarify 
that 'annotated tags' can be date sorted but lightweight tags can't.

Maybe Amiel could suggest a short documentation patch to that effect 
that would have helped as a new reader of that doc. In this case it's 
the omission that is easily missed.

>   Given the tags have identical
> timestamps, Git simply displays the one that's first alphabetically.
>
> Git does have some ability to parse versions and sort them, on newer
> versions, but there's no way to activate that via "git describe
> --tags", at least as far as I'm aware (and I'm not sure how reliable
> it can be, given tag names are essentially free-form text).
>
> You can try Git's version sorting with a command like "git tag
> --sort=-v:refname" (The "-" before "v:refname" sorts in descending
> order)
>
> incom@Jael MINGW64 /c/Temp/fourth.git (BARE:master)
> $ git tag
> v1
> v2
> incom@Jael MINGW64 /c/Temp/fourth.git (BARE:master)
> $ git tag --sort=-v:refname
> v2
> v1
>
> Since you can't enable that for "git describe --tags", though, I'm not
> sure it's helpful. (Someone else can correct me if there is a way to
> make "git describe" do that.)
>
> Bryan
>
> (Re-added the list on CC)
Philip


```
