git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git tag output order is incorrect (IMHO)

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 11, 2013, 17:54 UTC
Message-ID
<xmqqioy7tfba.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CABURp0o5tOswiv_avfAQOZwGREpX3v7MwcdVzt7dkubY2Y0O6g@mail.gmail.com>
Phil Hord <phil.hord@gmail.com> writes:
Show 10 quoted lines
> Someone at $work asked me this week how to find the current and
> previous tags on his branch so he could generate release notes.  I
> just need "last two tags on head in topo-order". I was surprised by
> how complicated this turned out to be. I ended up with this:
>
>   git log --decorate=full --pretty=format:'%d' HEAD |
>     sed -n -e 's-^.* refs/tags/\(.*\)[ )].*$-\1-p' |
>     head -2
>
> Surely there's a cleaner way, right?

That looks clean enough (I would have used "head -n 2" though) and in line with the way how you can exercise the flexibility of the system, at least to me ;-).

Joking aside, I agree that a "--merged X" primitive, i.e. "what refs can be reachable from commit X?", in the listing mode of "git tag" or "git for-each-ref" would have helped. As the sorting and formatting primitives are already there in for-each-ref, it would have been

	git for-each-ref \
            --format='%(refname:short)' \
            --sort='-*committerdate' \
            --count=2 \
            --merged my-branch \
            refs/tags/
or something like that.
Previous: Phil Hord
Message 16 of 16 in “Git tag output order is incorrect (IMHO)”
  1. Rahul BansalJul 18, 2013
  2. Duy NguyenJul 18, 2013
  3. Duy NguyenJul 18, 2013
  4. Rahul BansalJul 18, 2013
  5. Rahul BansalJul 18, 2013
  6. Duy NguyenJul 18, 2013
  7. Andreas SchwabJul 18, 2013
  8. Junio C HamanoJul 19, 2013
  9. Jeff KingJul 20, 2013
  10. Antoine PelisseAug 20, 2013
  11. Jeff KingSep 8, 2013
  12. Jeff KingOct 16, 2013
  13. Antoine PelisseOct 16, 2013
  14. Felipe ContrerasSep 8, 2013
  15. Phil HordSep 11, 2013
  16. Junio C HamanoSep 11, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.