Subject: Re: Feature Request: Passing a number as an option to git tags for displaying latest tags

From: Junio C Hamano <[email-masked]>
Date: Wed, 22 Jul 2015 12:17:19 -0700

Halil Öztürk <[email-masked]> writes:

> Passing a number as an option to "git tags" command should display latest tags.
>
> e.g. "git tags -5" will display last 5 tags only.

I think this conflates two unrelated things.

 - Ordering tags not by refnames (i.e. default) but by "time".

 - Limiting the output by count.

The latter is what "| head -n 5" and/or "| tail -n 5" are for, so it
would be at most "nice to have"; I am indifferent in the sense that
I won't work on it, but I'd take a look if somebody sent a patch
that was cleanly done.

The former, sort by "time", is interesting, but you need to define
what to do with various corner cases.  For example, some people may
be have one or more of the following desires:

 * My project did not use tags for a long time, and started using it
   recently starting from v1.1.0.  The first release only said
   "Frotz version 1.0.0" in its commit log message.  I retroactively
   did "git tag -s -m 'Frotz 1.1.0' v1.1.0" on that commit.

   In such a case, it is likely that I would want the sorting done
   based on the committer date on the underlying commit, not the
   tag's tagger date.

 * When a bug is found, it is customary in my project to add a
   "break-<something>" tag to the commit that introduces the bug
   (and "fix-<something>" tag to the commit that fixes it).

   When I want to find recently discovered breakages, I want the
   tags whose names match "break-*" sorted by tagger dates, not the
   underlying commit's committer dates.

The necessary ordering machinery to do the above already exists in
"for-each-ref".  There is a GSoC project that works to unify various
features spread across "for-each-ref", "branch -l" and "tag -l" and
make them available to all of the three.