我正在使用 git log 和自定义--pretty:format:
git --no-pager log --pretty=format:"%C(yellow)%h%Creset %s %Cgreen(%cr) %Cblue<%an>%Creset" -5
Run Code Online (Sandbox Code Playgroud)
产生这样的输出
7224466 update version (4 days ago) <Xerus>
3f00703 improve stuff (9 days ago) <Xerus>
Run Code Online (Sandbox Code Playgroud)
我还想查看提交的标签(如果它有任何与之关联的标签),例如 option --decorate,但我在格式文档中找不到任何关于标签的提及。
Xer*_*rus 14
您可以使用%d或%D,如git 文档中所述,进行漂亮的格式化。它们将显示引用名称,即与相应提交关联的分支和标签的名称。
您可能想要使用小写的 d,因为它会自动正确格式化 ref 以便在控制台中漂亮地显示,与 一起%C(auto),它会自动按照您习惯的方式为其着色。
将它们放在一起,您可以将命令修改为:
git --no-pager log --pretty=format:"%C(auto)%h%d - %s %Cgreen(%cr) %Cblue<%an>%Creset" -5
Run Code Online (Sandbox Code Playgroud)
这将导致这样的输出
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>
Run Code Online (Sandbox Code Playgroud)