Git: 如何根据相应提交的日期对标签进行排序?

Git: How to sort tags by the date of the corresponding commit?

轻量级标签可以使用(基于this answer

按相应提交的日期排序
git tag --sort=authordate

带注释的标签可以使用(基于this answer

按相应提交的日期排序
git tag --sort=*authordate

可以指定多个排序字段:

git tag --sort=authordate --sort=*authordate --format='[%(*authordate:iso)][%(authordate:iso)] %(refname:short)'

但这会将所有轻量级标签和所有带注释的标签组合在一起,因为 *authordate 对于轻量级标签是空的,而 authordate 对于带注释的标签是空的。所以我想我可能需要指定一个后备字段,如果另一个字段为空,则使用该字段代替另一个字段。 git 有这样的功能吗? (我在git tag --help里没找到。)

如何按相应提交的作者日期对所有标签(带注释的标签和轻量级标签的混合)进行排序?

彻底完成此操作的最快方法可能是

git tag --format='%(objectname)^{}' \
| git cat-file --batch-check \
| awk '=="commit" { print  }' \
| git log --stdin --author-date-order --no-walk --decorate --oneline

因为标签不必指向提交,所以您可以标记任何内容。 *authordate 指向标签的标签也将是空白的,尽管它(通常)最终解析为提交。

有关 ^{} revision-expression 语法,请参见 git help revisions