如何在 git 中列出所有标签以及完整消息?

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

How to list all tags along with the full message in git?

gittagsgit-tag

提问by still_dreaming_1

I want git to list all tags along with the full annotation or commit message. Something like this is close:

我希望 git 列出所有标签以及完整的注释或提交消息。像这样的事情很接近:

git tag -n5

This does exactly what I want except that it will only show up to the first 5 lines of the tag message.

这正是我想要的,只是它只会显示标签消息的前 5 行。

I guess I can just use a very large number. What is the highest number I can use here? Is it the same on every computer?

我想我可以使用一个非常大的数字。我在这里可以使用的最高数字是多少?是不是每台电脑都一样?

UPDATE: I have had much time to think about this, and now I think I don't necessarily want to show the entirety of each message if some of them are extraordinarily long. I didn't really have any particular need that required me to see massive messages (other than my own propensity to be long winded in everything I write, including tag messages). I just didn't like the idea that it was not necessarily going to show me the whole message, as that made me feel like it was hiding information from me. But too much information can also be a bad thing.

更新:我有很多时间考虑这个问题,现在我认为如果其中一些消息特别长,我不一定要显示每条消息的全部内容。我真的没有什么特别的需要需要我看到大量的消息(除了我自己写的所有东西都长篇大论的倾向,包括标签消息)。我只是不喜欢它不一定会向我展示整个信息的想法,因为这让我觉得它在向我隐藏信息。但过多的信息也可能是一件坏事。

采纳答案by still_dreaming_1

git tag -n99

Short and sweet. This will list up to 99 lines from each tag annotation/commit message. Here is a link to the official documentation for git tag.

简短而甜蜜。这将从每个标记注释/提交消息中列出最多 99 行。这是 git tag 官方文档的链接

I now think the limitation of only showing up to 99 lines per tag is actually a good thing as most of the time, if there were really more than 99 lines for a single tag, you wouldn't really want to see all the rest of the lines would you? If you did want to see more than 99 lines per tag, you could always increase this to a larger number.

我现在认为每个标签最多只能显示 99 行的限制实际上是一件好事,因为在大多数情况下,如果单个标签真的超过 99 行,你就不会真的想看到所有其余的你会吗?如果您确实希望每个标签超过 99 行,您可以随时将其增加到更大的数字。

I mean, I guess there could be a specific situation or reason to want to see massive tag messages, but at what point do you notwant to see the whole message? When it has more than 999 lines? 10,000? 1,000,000? My point is, it typically makes sense to have a cap on how many lines you would see, and this number allows you to set that.

我的意思是,我猜有可能是一个具体的情况或理由希望看到大量标签的信息,但在什么时候,你希望看到整条消息?当它有超过 999 行时?10,000?1,000,000?我的观点是,对您将看到的行数设置上限通常是有意义的,这个数字允许您进行设置。

Since I am making an argument for what you generally want to see when looking at your tags, it probably makes sense to set something like this as an alias (from Iulian Onofrei's comment below):

由于我正在论证您在查看标签时通常希望看到的内容,因此将这样的内容设置为别名可能是有意义的(来自以下 Iulian Onofrei 的评论):

git config --global alias.tags 'tag -n99'

git config --global alias.tags 'tag -n99'

I mean, you don't really want to have to type in git tag -n99every time you just want to see your tags do you? Once that alias is configured, whenever you want to see your tags, you would just type git tagsinto your terminal. Personally, I prefer to take things a step further than this and create even more abbreviated bash aliases for all my commonly used commands. For that purpose, you could add something like this to your .bashrc file (works on Linux and similar environments):

我的意思是,您真的不想git tag -n99每次只想查看标签时都输入,是吗?一旦配置了该别名,无论何时您想查看标签,您只需git tags在终端中输入即可。就我个人而言,我更喜欢比这更进一步,为我所有常用的命令创建更简短的 bash 别名。为此,您可以在 .bashrc 文件中添加如下内容(适用于 Linux 和类似环境):

alias gtag='git tag -n99'

alias gtag='git tag -n99'

Then whenever you want to see your tags, you just type gtag. Another advantage of going down the alias path (either git aliases or bash aliases or whatever) is you now have a spot already in place where you can add further customizations to how you personally, generally want to have your tags shown to you (like sorting them in certain ways as in my comment below, etc). Once you get over the hurtle of creating your first alias, you will now realize how easy it is to create more of them for other things you like to work in a customized way, like git log, but let's save that one for a different question/answer.

然后,每当您想查看标签时,只需键入gtag. 沿着别名路径(git 别名或 bash 别名或其他任何)的另一个优点是,您现在已经有了一个位置,您可以在其中添加进一步的自定义以您的个人方式,通常希望向您显示您的标签(例如排序他们以某些方式,如我在下面的评论等)。一旦您克服了创建第一个别名的麻烦,您现在就会意识到为您喜欢以自定义方式工作的其他事情创建更多别名是多么容易,例如git log,但让我们将其保存为不同的问题/答案.

回答by Zubair

Try this it will list all the tags along with annotations & 9 lines of message for every tag:

试试这个,它将列出所有标签以及每个标签的注释和 9 行消息:

git tag -n9

can also use

也可以使用

git tag -l -n9

if specific tags are to list:

如果要列出特定标签:

git tag -l -n9 v3.*

(e.g, above command will only display tags starting with "v3.")

(例如,上面的命令只会显示以“v3”开头的标签。)

-l , --list List tags with names that match the given pattern (or all if no pattern is given). Running "git tag" without arguments also lists all tags. The pattern is a shell wildcard (i.e., matched using fnmatch(3)). Multiple patterns may be given; if any of them matches, the tag is shown.

-l , --list 列出名称与给定模式匹配的标签(如果没有给出模式,则全部匹配)。不带参数运行“git tag”也会列出所有标签。该模式是一个 shell 通配符(即,使用 fnmatch(3) 进行匹配)。可以给出多个模式;如果其中任何一个匹配,则显示标签。

回答by Paul Price

Mark Longair's answer(using git show) is close to what is desired in the question. However, it also includes the commit pointed at by the tag, along with the full patch for that commit. Since the commit can be somewhat unrelated to the tag (it's only one commit that the tag is attempting to capture), this may be undesirable. I believe the following is a bit nicer:

Mark Longair 的回答(使用git show)接近问题中的要求。但是,它还包括标记指向的提交,以及该提交的完整补丁。由于提交可能与标签无关(它只是标签试图捕获的一个提交),因此这可能是不可取的。我相信以下内容更好一些:

for t in `git tag -l`; do git cat-file -p `git rev-parse $t`; done

回答by Mark Longair

It's far from pretty, but you could create a script or an alias that does something like this:

它远非漂亮,但您可以创建一个脚本或别名来执行以下操作:

for c in $(git for-each-ref refs/tags/ --format='%(refname)'); do echo $c; git show --quiet "$c"; echo; done

回答by gaRex

Last tag message only:

仅最后标记消息:

git cat-file -p $(git rev-parse $(git tag -l | tail -n1)) | tail -n +6

回答by Александр Туманов

Use --format option

使用 --format 选项

git tag -l --format='%(tag) %(subject)'

回答by agouge

I prefer doing this on the command line, but if you don't mind a web interface and you use GitHub, you can visit https://github.com/user/repo/tagsand click on the "..." next to each tag to display its annotation.

我更喜欢在命令行上执行此操作,但如果您不介意 Web 界面并且使用 GitHub,则可以访问https://github.com/user/repo/tags并单击每个标签旁边的“...”以显示其注释。