我想要git列出所有标签连同完整的注释或提交消息。类似这样的事情很接近:

git tag -n5

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

我想我可以用一个很大的数。这里最大的数是多少?每台电脑都一样吗?

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.


当前回答

Mark Longair的答案(使用git show)接近于问题中的期望。但是,它还包括标记所指向的提交,以及该提交的完整补丁。由于提交可能与标记有点不相关(标记只试图捕获一次提交),这可能是不可取的。我相信下面的内容会更好:

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

其他回答

使用——format选项

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

我更喜欢在命令行上做这件事,但如果你不介意web界面,并且你使用GitHub,你可以访问https://github.com/user/repo/tags,然后点击每个标签旁边的“…”来显示它的注释。

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

or

git for-each-ref refs/tags/ --format='%(contents)'

将为每个标签输出完整的注释消息(如果已签名,则包括签名)。

%(contents:subject)将只输出第一行 %(内容:正文)将输出没有第一行和签名的注释(仅有用文本) %(内容:签名)将只输出pgp签名

详见man get -for-each-ref“字段名”部分。

它远非漂亮,但你可以创建一个脚本或别名,这样做:

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

仅限最后标签信息:

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