【问题标题】:How to override a git log pretty format?如何覆盖 git log 漂亮格式?
【发布时间】:2017-03-21 15:26:38
【问题描述】:

可用的内置漂亮格式并不完全符合我的需要(或我的口味):

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

git log --decorate --graph --all --pretty=short 几乎是我想要的,但我也希望显示提交日期...

git log --decorate --graph --all --pretty=medium 很好,但我不想完整的提交消息。我只想显示提交消息的第一行...


所以我尝试定义自己的漂亮格式,就像 'medium' 但没有完整的提交消息,如下所示:

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

一个问题是分支名称不再显示。另一个问题是原木不再有颜色了。我怎样才能正确地做到这一点?

理想情况下,我只想覆盖 --pretty=medium,这样它就不会显示完整的提交消息,而只会显示提交的标题(或覆盖 --pretty=short 显示日期)。这是唯一可能的(覆盖一种内置的漂亮格式)吗?如果是,怎么做?

【问题讨论】:

    标签: git git-log


    【解决方案1】:

    --decorate 不适用于自己的格式。如果需要,需要使用%d%D。如果你喜欢,你还可以添加一些颜色来获得类似的输出,比如中等,你可能想要这样的东西:

    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'
    

    【讨论】:

    • 如果 HEAD、-> 有不同的颜色,则可能更接近内置 --decorate。几乎完美的搭配!迄今为止最好的答案。谢谢。 +1
    • 是的,但是我没有找到彩色装饰物的标记,所以你只能整体做。
    猜你喜欢
    • 2017-06-30
    • 2021-03-30
    • 1970-01-01
    • 2021-02-28
    • 2013-03-05
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    相关资源
    最近更新 更多