threads / discuss / 50864

Fw: git describe issue

Subject: Fw: git describe issue

## tl;dr

4 messages between Apr 3, 2019 and Apr 3, 2019.

replies: 3people: 3as markdown or json

Amiel Elboim· Apr 3, 2019, 06:47 UTC · lore
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· Apr 3, 2019, 06:59 UTC · re: Amiel Elboim · lore

Re: Fw: git describe issue

On Tue, Apr 2, 2019 at 11:47 PM Amiel Elboim <amielel@matrix.co.il> wrote:
Show 14 quoted lines
> 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· Apr 3, 2019, 08:11 UTC · lore

Re: Fw: git describe issue

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· Apr 3, 2019, 09:19 UTC · re: Bryan Turner · lore

Re: Fw: git describe issue

On 03/04/2019 09:11, Bryan Turner wrote:
Show 6 quoted lines
> 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.

Show 28 quoted lines
>   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

← back to recent threads