如何按创建日期列出 Git 存储库中的所有标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6269927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:07:26  来源:igfitidea点击:

How can I list all tags in my Git repository by the date they were created?

git

提问by Jon Ursenbach

I need some way to list all tags in my system by the date they were created but am not sure if I can get that data via git-log. Ideas?

我需要某种方法来按创建日期列出系统中的所有标签,但不确定是否可以通过 git-log 获取该数据。想法?

回答by Josh Lee

Sorting by tag creation date works with annotated and lightweight tags:

按标签创建日期排序适用于带注释和轻量级标签:

git for-each-ref --sort=creatordate --format '%(refname) %(creatordate)' refs/tags

回答by VonC

Git 2.8 (March 2016) documents another option dating back to git 1.4.4 (Oct2006).
See commit e914ef0(05 Jan 2016) by Eric Wong (ele828).
(Merged by Junio C Hamano -- gitster--in commit 108cb77, 20 Jan 2016)

Git 2.8(2016 年 3 月)记录了另一个可追溯到 git 1.4.4 (Oct2006) 的选项
请参阅Eric Wong ( )提交的 e914ef0(2016 年 1 月 5 日)(由Junio C Hamano合并-- --commit 108cb77,2016 年 1 月 20 日)ele828
gitster

See the new Documentation/git-for-each-ref.txt

看到新的 Documentation/git-for-each-ref.txt

For commit and tag objects, the special creatordateand creatorfields will correspond to the appropriate date or name-email-date tuple from the committeror taggerfields depending on the object type.
These are intended for working on a mix of annotated and lightweight tags.

对于提交和标签的对象,特殊creatordatecreator领域将对应于从适当的日期或名称,电子邮件最新的元组committertagger域取决于对象类型。
这些用于处理带注释和轻量级标签的混合

So using creatordateworks with tags:

所以使用creatordate带有标签的作品:

git for-each-ref --format='%(*creatordate:raw)%(creatordate:raw) %(refname) %(*objectname) %(objectname)' refs/tags | \
sort -n | awk '{ print , ; }' 

Or:

或者:

git tag --sort=-creatordate 


As I detail in "How to sort git tags by version string order of form rc-X.Y.Z.W?", you can add a sort order to git tag(since Git 2.0 June 2014).

正如我在“如何按 rc-XYZW 表单的版本字符串顺序对 git 标签进行排序?”中详细说明的那样,您可以向git tag(自 Git 2.0 2014 年 6 月起)添加排序顺序。

That sort order includes as field name (listed in git for-each-ref)taggerdate. That allows for git tag --sort=taggerdate(mentioned by DarVarbelow)
As an example, in the git/gitrepoit will list the v2.10.0tag last:

该排序顺序包括作为字段名称(在 中列出git for-each-reftaggerdate。这允许git tag --sort=taggerdate(由下面DarVar提到) 作为一个例子,在repo 中它会最后列出标签:
git/gitv2.10.0

v2.9.1
v2.9.2
v2.9.3
v2.10.0-rc0
v2.10.0-rc1
v2.10.0-rc2
v2.10.0

The default order would not (git tag):

默认顺序不会 ( git tag):

v2.1.2
v2.1.3
v2.1.4
v2.10.0
v2.10.0-rc0
v2.10.0-rc1
v2.10.0-rc2
v2.2.0

回答by gavenkoa

git log --tags --simplify-by-decoration --pretty="format:%ci %d"

Also nice output from (without date field):

也不错的输出(没有日期字段):

git log --tags --decorate --simplify-by-decoration --oneline

To see full history with dependencies and striped linear commits (only essential events, like tagging and branching/merging):

要查看具有依赖项和条带化线性提交的完整历史记录(仅必要事件,例如标记和分支/合并):

git log --graph --decorate --simplify-by-decoration --oneline --all

回答by elboulangero

This one-liner displays dates & tags without any fuss.

这个单行显示日期和标签没有任何大惊小怪。

git tag --format='%(creatordate:short)%09%(refname:strip=2)'

Output:

输出:

2015-04-01  storaged-2.0.0
2015-06-11  storaged-2.1.0
2015-08-06  storaged-2.1.1
...

If you don't like how tags are sorted by default, you can sort by date with the option --sort=creatordate, for example. See VonC answerfor more details.

例如,如果您不喜欢标签的默认排序方式,则可以使用选项按日期排序--sort=creatordate。有关更多详细信息,请参阅VonC 答案

回答by Zamicol

git tag --sort=-taggerdate

According to the man page, "Prefix - to sort in descending order of the value. "

根据手册页,“前缀 - 按值的降序排序。”

git taguses the same sorting keys as git-for-each-ref, which is where the keys are documented.

git tag使用与 相同的排序键git-for-each-ref,这是记录键的地方。

回答by Yann Droneaud

To have annotated tags and lightweight tags sorted altogether, based on the commit date, I'm using:

要根据提交日期对带注释的标签和轻量级标签进行排序,我正在使用:

git for-each-ref --format='%(*committerdate:raw)%(committerdate:raw) %(refname) %(*objectname) %(objectname)' refs/tags | \
  sort -n | awk '{ print , ; }' 

This command will list every tag and the associated commit object id, in chronological order.

此命令将按时间顺序列出每个标签和相关的提交对象 ID。

回答by DarVar

With Git version 2.10.0.windows.1

使用 Git version 2.10.0.windows.1

git tag --sort=taggerdate

git tag --sort=taggerdate

回答by Andrew McGlashan

The following relies on the commit, so it doesn't matter if it has date information with the commit:

以下依赖于提交,因此它是否具有提交的日期信息并不重要:

git log --tags --decorate --simplify-by-decoration|grep ^commit|grep tag|sed -e 's/^.*: //' -e 's/)$//' -e 's/,.*$//'|tac

The answer above by Josh Lee, relies on a tag date to get the order correct.

Josh Lee 的上述答案依赖于标记日期来使订单正确。

回答by Ville

Building on the earlier mentioned methods, I wanted to also see the actual tag date on the list, and so my in-use version is:

在前面提到的方法的基础上,我还想查看列表中的实际标签日期,因此我使用的版本是:

git for-each-ref --format='%(*creatordate:raw)%(creatordate:raw) %(creatordate:short) %(refname) %(*objectname) %(objectname)' refs/tags | sort -n | awk '{ print , ,  }'