简体   繁体   English

如何覆盖git日志漂亮的格式?

[英]How to override a git log pretty format?

The available built-in pretty formats don't exactly fit my need (or my taste): 可用的内置漂亮格式并不完全符合我的需要(或我的口味):

https://git-scm.com/docs/pretty-formats https://git-scm.com/docs/pretty-formats

git log --decorate --graph --all --pretty=short is almost what I want, but I'd like the commit date to be shown as well... git log --decorate --graph --all --pretty=short几乎就是我想要的,但是我想要显示提交日期......

git log --decorate --graph --all --pretty=medium is nice, but I don't want to the full commit message. git log --decorate --graph --all --pretty=medium很好,但我不想要完整的提交消息。 I'd like only the first line of the commit message to be shown... 我只想显示提交消息的第一行......


So I tried to define my own pretty format, just like 'medium' but without the full commit message, like so: 所以我尝试定义我自己的漂亮格式,就像'medium'但没有完整的提交消息,如下所示:

git log --decorate --graph --all --pretty=format:'commit %H%nAuthor: %an%nDate: %ad%n%n%s%n'

One problem is the branch names are not shown anymore. 一个问题是分支名称不再显示。 Another problem is the logs are not in color anymore. 另一个问题是原木不再是颜色了。 How can I do that correctly? 我怎么能正确地做到这一点?

Ideally, I'd just like to override --pretty=medium so that it will not show the full commit message, but only the title of the commit (or to override --pretty=short for it to show the date). 理想情况下,我只想覆盖 --pretty=medium以便它不会显示完整的提交消息,而只显示提交的标题(或覆盖 --pretty=short以显示日期)。 Is this only possible (to override a built-in pretty format)? 这是唯一可能的( 覆盖内置的漂亮格式)吗? If yes, how? 如果有,怎么样?

--decorate does not work with an own format. --decorate不适用于自己的格式。 If you want it, you need to use %d or %D . 如果需要,您需要使用%d%D And if you like you can also add some coloring to get similar output like for medium you probably want something like: 如果你喜欢你也可以添加一些着色来获得类似的输出,如中等你可能想要的东西:

git log --graph --all --pretty=format:'%C(auto,yellow)commit %H%C(auto,green bold)%d%Creset%nAuthor: %an%nDate: %ad%n%n%s%n'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM