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.