列出 git 标签名称、日期和消息

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

List git tag names, dates and messages

gitgit-loggit-tag

提问by kayaker243

How do I list the tag name, tag date and tag message for all tags?

如何列出所有标签的标签名称、标签日期和标签消息?

It seems that git's separation of display logic for commits through git logand tags through git tagmakes it difficult to list the tag name, the tag's date and the tag message.

似乎 git 对 commits throughgit log和 tags through的显示逻辑的分离git tag使得列出标签名称、标签日期和标签消息变得困难。

I can show the tag date, name and commit messageusing git log --tags --show-notes --simplify-by-decoration --pretty="format:%ai %d %s"

我可以显示标签日期,名称和提交信息使用git log --tags --show-notes --simplify-by-decoration --pretty="format:%ai %d %s"

I inspected http://opensource.apple.com/source/Git/Git-26/src/git-htmldocs/pretty-formats.txtbut didn't see any option to show tag message.

我检查了http://opensource.apple.com/source/Git/Git-26/src/git-htmldocs/pretty-formats.txt但没有看到任何显示标签消息的选项。

I can show the tag name and 5 lines of tag messageusing git tag -n5.

我可以显示标签名和5号线的标记信息使用git tag -n5

But to get all three pieces of info would appear to require gnarly scripting beyond my ability.

但是要获得所有三条信息似乎需要超出我能力范围的粗糙脚本。

回答by Andrew C

You want to use the for-each-refcommand. Unfortunately, it's only slightly less user friendly than filter-branch

您要使用该for-each-ref命令。不幸的是,它的用户友好性仅略低于filter-branch

Note that information like tag date and the tagger is only available for annotated tags.

请注意,标记日期和标记器等信息仅适用于带注释的标记。

Below is a basic prototype. Note that the format= can be an entire shell script of its own, and probably should be depending on how complicated you want the output. They have a couple of examples specifically for tags in the for-each-ref documentation

下面是一个基本的原型。请注意, format= 可以是它自己的整个 shell 脚本,并且可能应该取决于您想要输出的复杂程度。他们在 for-each-ref 文档中有几个专门针对标签的示例

git for-each-ref --format="%(refname:short) %(taggerdate) %(subject) %(body)" refs/tags

回答by Christopher

git show --tagswill at least output all the relevant information about your tags. You might be able to find an appropriate --pretty=format:sequence from there.

git show --tags至少会输出关于你的标签的所有相关信息。您也许可以--pretty=format:从那里找到合适的序列。

回答by Claudio Floreani

I don't know if there's a way to

不知道有没有办法

list onlythe tag name, tag date and tag message for all tags using only the git syntax.

使用 git 语法列出所有标签的标签名称、标签日期和标签消息 。

But a simple grep will do the job:

但是一个简单的 grep 就可以完成这项工作:

git show --tags |grep "^tag " -A4

git show --tags |grep "^tag " -A4

Notice I specify 4 lines of trailing context after matching, because the standard output shows tag name, tag date and tag message each on a separate line.

请注意,我在匹配后指定了 4 行尾随上下文,因为标准输出在单独的一行中显示了标签名称、标签日期和标签消息。

If you need to deal with multiline tag messages I would prefer using piping to awk which is slightly more cumbersome:

如果您需要处理多行标记消息,我更喜欢使用管道到 awk,这稍微麻烦一点:

git show --tags |awk "/^tag /,/-----BEGIN PGP SIGNATURE-----|commit /" |egrep -v "^$" |sed -E "s/^-----BEGIN PGP SIGNATURE-----.*|^commit.*/-/"

git show --tags |awk "/^tag /,/-----BEGIN PGP SIGNATURE-----|commit /" |egrep -v "^$" |sed -E "s/^-----BEGIN PGP SIGNATURE-----.*|^commit.*/-/"

This will work as long as the tag message is followed by either the PGP SIGNATURE or the commit message, which afaik are all the possibile situations. However, you can easily adapt the last grep to cover other situations (if there were to be).

只要标签消息后跟 PGP 签名或提交消息,这将起作用,这是所有可能的情况。但是,您可以轻松地调整最后一个 grep 以涵盖其他情况(如果有的话)。

回答by sepehr

How about a bit nicer colorful format?

更好一点的彩色格式怎么样?

# ~/.gitconfig
[alias]
tags="for-each-ref --sort=taggerdate --format=%(color:green)%(subject)%(color:reset), tagged: %(refname:short)\n%(taggerdate)\n%(taggername) %(taggeremail)\n\n%(contents:body)\n' refs/tags"


$ git tags 

Release 1.0.1, tagged: 1.0.1
Wed Jul 4 20:16:05 2018 +0430
Sepehr Lajevardi <sepehr.lajevardi@...>

Changelog
- Implement Contentful webhooks to purge internal and CF caches.
- Implement CloudFlareService.
- Fix Contentful's mapping concern usage/namespace. #73
- Temporarily enforce https in og:url property. #103
- Fix entry callback issue with Contentful client. #99
- Fix issue with PPM docker build. #96

Release 1.1.2, tagged: 1.1.2
Thu Jul 12 21:26:29 2018 +0430
Sepehr Lajevardi <sepehr.lajevardi@...>

Changelog
- Fix GA share event issue with AddThis. #132
- Optimize OpenGraph protocol tags for articles. #130
- Optimize Twitter card tags. #131
- Fix HTML validation errors as much as possible. #127


Release 1.1.3, tagged: 1.1.3
Mon Jul 16 22:49:05 2018 +0430
Sepehr Lajevardi <sepehr.lajevardi@...>

Changelog
- Implement cross-device/browser fav/home icons. #137, #138
- Minify HTML output of all pages. #139
- Check for lighthouse score in build pipeline. #30
- Drop AddThis in favor of in-house ShareBar. #116
- Minor article OG tag adjustments.

回答by Omisha gupta

If you want to fetch the latest tag details, use --sortflag, remember that if you are sorting on dates, use '-' before the date to list the newest first.

如果您想获取最新的标签详细信息,请使用--sort标志,请记住,如果您按日期排序,请在日期前使用“-”以首先列出最新的。

For example, I wanted the latest tag description (as it happens to be the latest release name), I used --format to just pull the subject of the tag and sort it taggerdate wise (newest first). Here's the command for that.

例如,我想要最新的标签描述(因为它恰好是最新的版本名称),我使用 --format 来提取标签的主题并按标签日期对其进行排序(最新的在前)。这是命令。

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

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

回答by San

This is rather a follow up question to Andrew'sresponse, slightly different but related topic.

这是安德鲁回答的后续问题,略有不同但相关的主题。

git for-each-ref --format="%(refname:short) %(taggerdate) %(subject) %(body)" refs/tags

git for-each-ref --format="%(refname:short) %(taggerdate) %(subject) %(body)" refs/tags

This works great on direct command line. When I set a git alias in ~/.gitconfig, it does not seem to spew the same output.

这在直接命令行上效果很好。当我在 ~/.gitconfig 中设置 git 别名时,它似乎没有输出相同的输出。

When invoked on command line directly, I get.

当直接在命令行上调用时,我得到了。

package-release-14.7.2 Wed Dec 3 14:24:38 2014 -0800 14.7.2: copy for tag package-release-14.7.2
package-release-14.7.3 Thu Dec 4 14:14:55 2014 -0800 14.7.3: copy for tag package-release-14.7.3
package-release-14.7.4 Fri Dec 5 16:16:40 2014 -0800 14.7.4: copy for tag package-release-14.7.4

package-release-14.7.2 Wed Dec 3 14:24:38 2014 -0800 14.7.2:复制标签 package-release-14.7.2
package-release-14.7.3 Thu Dec 4 14:14:55 2014 -0800 14.7.3:复制标记 package-release-14.7.3
package-release-14.7.4 Fri Dec 5 16:16:40 2014 -0800 14.7.4:复制标记 package-release-14.7.4

And when I invoke a git alias(taghist = for-each-ref --format="%(refname:short) %(taggerdate) %(subject) %(body)" refs/tags), I get

当我调用 git alias(taghist = for-each-ref --format="%(refname:short) %(taggerdate) %(subject) %(body)" refs/tags) 时,我得到

package-release-14.7.2
package-release-14.7.3
package-release-14.7.4

package-release-14.7.2
package-release-14.7.3
package-release-14.7.4

-San

-San