Thread (1 message) 1 message, 1 author, 2016-06-15

Re: Git tag output order is incorrect (IMHO)

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:58:43

Phil Hord [off-list ref] writes:
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help