你如何列出 git 提交,它们的标签在输出中交错?

how do you list git commits with their tags interleaved in the output?

我有一些代码得到了很多提交并且也经常被标记。

我想看看每个标签的提交是什么,然后我将在标签之间做一个 git 差异以查看实际的代码更改。

你如何列出 git 提交,它们的标签在输出中交错?


我在想像这样的输出会让我看到每个标签的提交是什么:

${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${tag_name} ${tag_date}
${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${tag_name} ${tag_date}

然而这个输出并不是一个严格的要求。这只是我想出的一个想法,它可以帮助我了解每个标签的提交内容。

可能有一些简单的 git 命令已经完成了我所要求的大部分操作,这些命令可能真的 easy/straight-forward。

您真的不希望标签交错。您需要在标记之前以日志格式换行。考虑到这一点,只需执行以下操作:

git log --format=format:'%h %ci %s%+D'

来自 git-log 文档:如果您在占位符的 % 之后添加 +(加号),当且仅当占位符扩展为非空字符串。