How to make git log cut long comments?

后端 未结 7 1061
执笔经年
执笔经年 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:19

    It is not that clear in the documentation just which characters are needed but the following example cuts the subject line to 50 characters:

    git log --oneline --format="%h %<(50,trunc)%s"
    

    The format specification is %< and the arguments for that need to be in parentheses. In this case, 50 chars and truncate the excess.

    For instance, performing this on the msysGit repository yields:

    C:\src\msysgit>git log -n 5 --format="%h [%<(12,trunc)%aN] [%<(12,trunc)%cN] %<(50,trunc)%s"
    
    218ed04 [Sebastian ..] [Sebastian ..] Merge pull request #154 from csware/tortoisegitp..
    8a920b9 [Sven Stric..] [Sven Stric..] Installer: Detect TortoiseGitPlink from Tortoise..
    448e125 [dscho       ] [dscho       ] Merge pull request #152 from csware/syscommand
    db8d1bf [Sven Stric..] [Sven Stric..] Perl readline creates empty sys$command files if..
    753d3d6 [Johannes S..] [Johannes S..] Git for Windows 1.8.5.2-preview20131230
    

提交回复
热议问题