`git tag` 按指向的提交日期的时间顺序排序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18659959/
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 16:53:46  来源:igfitidea点击:

`git tag` sorted in chronological order of the date of the commit pointed to

gitsorting

提问by soerface

The output from git tagis ordered alphabetically. I would like it to be ordered chronological (the date of the commits they are assigned to, not the date on which they were created), otherwise the output should stay the same.

from 的输出git tag按字母顺序排列。我希望它按时间顺序排序(它们被分配到的提交日期,而不是它们的创建日期),否则输出应该保持不变。

I've tried the suggestion from http://networkadmin20.blogspot.de/2010/08/howto-list-git-tags-by-date.html, but the order is still the same.

我已经尝试了http://networkadmin20.blogspot.de/2010/08/howto-list-git-tags-by-date.html的建议,但顺序还是一样。

To make sure it is not an error with my repository, I tried the following with a clean repository:

为了确保它不是我的存储库的错误,我在一个干净的存储库中尝试了以下操作:

soeren@ubuntu ~/Projects/sandbox % mkdir chronogit
soeren@ubuntu ~/Projects/sandbox % cd chronogit 
soeren@ubuntu ~/Projects/sandbox/chronogit % git init
Initialized empty Git repository in /home/soeren/Projects/sandbox/chronogit/.git/
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % touch a
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git add a
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git commit -m 'a'
[master (root-commit) f88e0e9] a
 0 files changed
 create mode 100644 a
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git tag 'A-first'
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git mv a b
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git commit -m 'c'
[master ecc0c08] c
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename a => b (100%)
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git tag 'C-second'
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git mv b c
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git commit -m 'b'
[master e72682d] b
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename b => c (100%)
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git tag 'B-third'
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git tag
A-first
B-third
C-second
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git for-each-ref refs/tags --sort=taggerdate --format="%(refname:short)"
A-first
B-third
C-second

The desired output is:

所需的输出是:

A-first
C-second
B-third

or, since inverting it shouldn't be too hard:

或者,因为反转它不应该太难:

B-third
C-second
A-first

Edit:As pointed out in the comments, this questionis pretty similiar, so I tried the following:

编辑:正如评论中所指出的,这个问题非常相似,所以我尝试了以下操作:

soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git log --tags --simplify-by-decoration --pretty="format:%ai %d"          
2013-09-06 16:08:43 +0200  (HEAD, B-third, master)
2013-09-06 16:08:21 +0200  (C-second)
2013-09-06 16:07:42 +0200  (A-first)

The order is fine, but now I'm fighting with the formatting…

订单很好,但现在我正在与格式作斗争......

soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git log --tags --simplify-by-decoration --pretty="format:%(refname:short)"
%(refname:short)
%(refname:short)
%(refname:short)
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git log --tags --simplify-by-decoration --format="%(refname:short)" 
%(refname:short)
%(refname:short)
%(refname:short)

采纳答案by soerface

git tag | xargs -I@ git log --format=format:"%ai @%n" -1 @ | sort | awk '{print }'

回答by rraval

Just tested with git 2.8.0:

刚刚用 git 2.8.0 测试过:

git tag --sort=committerdate

For a full list of field names you can use, see https://git-scm.com/docs/git-for-each-ref#_field_names

有关您可以使用的字段名称的完整列表,请参阅https://git-scm.com/docs/git-for-each-ref#_field_names

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

Fields that have name-email-date tuple as its value (author, committer, and tagger) can be suffixed with name, email, and dateto extract the named component.

对于提交和标记对象,特殊creatordatecreator字段将对应于来自提交者或标记者字段的适当日期或姓名-电子邮件-日期元组,具体取决于对象类型。这些旨在处理带注释和轻量级标签的混合。

有名字的电子邮件最新的元组作为其值的字段(authorcommitter,和tagger)可以与后缀nameemail以及date提取命名组件。

回答by opsidao

In git 2.3.3 I can just do this to get them sorted by date:

在 git 2.3.3 中,我可以这样做以使它们按日期排序:

git tag --sort version:refname

PS: For the record, I also answered the same thing on a duplicatequestion

PS:为了记录,我也在一个重复的问题上回答了同样的事情

回答by seacoder

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

回答by John Zhang

Try this:

尝试这个:

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

It works perfectly and very fast for me.

它对我来说完美且非常快。

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

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

回答by mwallner

As Alexander pointed outit should be

正如亚历山大指出的那样应该是

git tag --sort=taggerdate

for correct chronological order.

为了正确的时间顺序。

edit: * iff you're interested in the date the tags where pushed, if you're interested in the date of the commits, it should be "commiterdate"

编辑:*如果您对推送标签的日期感兴趣,如果您对提交日期感兴趣,则应该是“commiterdate”

回答by rfrerebe

For information, to get it in reverse order, prefix it with "-"

有关信息,要以相反的顺序获取它,请在其前面加上“-”

git tag --sort=-taggerdate