How to make git log cut long comments?

后端 未结 7 1049
执笔经年
执笔经年 2020-12-14 14:43

I have a git log alias that prints each commit as a single line. Since some people write far too long one-liners in the commit log, many commits wrap to a new line. How can

7条回答
  •  心在旅途
    2020-12-14 15:23

    I put this into ~/bin/git-mylog:

    #!/bin/bash
    COLS=$(tput cols)
    git log --format="tformat:%>|(15)%C(auto)%h %Cgreen %<(20,trunc)%cn %C(auto) %<(15,trunc)%ar %<($((COLS-55)),trunc)%s" --graph
    

    There's a bit going on here, but the guts of it is to use tput cols to get the terminal width and then do some arithmetic to truncate the comment width to the actual space available rather than a fixed width.

提交回复
热议问题