如何以自定义 git 日志格式显示标签?

2024-01-08

情况

我正在使用 git log 和自定义--pretty:format:

 git --no-pager log --pretty=format:"%C(yellow)%h%Creset %s %Cgreen(%cr) %Cblue<%an>%Creset" -5

产生这样的输出

7224466 update version (4 days ago) <Xerus>
3f00703 improve stuff (9 days ago) <Xerus>

Problem

我还想查看提交的标签(如果它有任何关联),例如选项--decorate,但我在格式化文档中找不到任何关于标签的提及。


您可以使用%d or %D,正如在git 文档用于漂亮的格式设置 https://git-scm.com/docs/pretty-formats。它们将显示引用名称,即与相应提交关联的分支和标签的名称。

您可能想要使用小写 d,因为它会自动正确格式化 ref 以便在控制台中漂亮地显示,以及%C(auto),它会自动按照您习惯的方式为其着色。

将它们放在一起,您可以将命令修改为:

 git --no-pager log --pretty=format:"%C(auto)%h%d - %s %Cgreen(%cr) %Cblue<%an>%Creset" -5

这将导致这样的输出

a2b8f3c (HEAD -> master, origin/master) - refactor: rename variable snackbarTextCache (8 weeks ago) <Xerus>
51a90be (tag: dev116-51a90be) - Fix connect.sid instructions (3 months ago) <Xerus>
fc372c3 - Update dependencies (3 months ago) <Xerus>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何以自定义 git 日志格式显示标签? 的相关文章

随机推荐