如何让git log减少长评论? [英] How to make git log cut long comments?

查看:239
本文介绍了如何让git log减少长评论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git日志别名,它将每个提交打印为一行。由于有些人在提交日志中写了太长的一行,很多提交都换行。我怎样才能格式化Git日志输出以剪切50个字符后的注释?



我在git-log手册页中找到了它,但它只会填充短注释,而不是

 %<( [,trunc | ltrunc | mtrunc]):使下一个占位符如有必要,至少需要N列,右侧为
填充空格。如果输出长于N列,可以选择在开始处截断(ltrunc),
中间(mtrunc)或结束(trunc)。请注意,
截断仅适用于N> = 2。


解决方案

 

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

格式规范是%< ,其参数需要放在括号内。例如,在msysGit存储库上执行此操作会产生以下结果:




pre> C:\ src \msysgit> git log -n 5 --format =%h [%<(12,trunc)%aN] [%<(12 ,TRUNC)%CN]%≤(50,TRUNC)%S

218ed04 [塞巴斯蒂安..] [塞巴斯蒂安..]从csware / tortoisegitp .. $ b $合并拉动请求#154 b 8a920b9 [斯文STRIC ..] [斯文STRIC ..安装程序:从龟检测TortoiseGitPlink ..
448e125 [dscho] [dscho]合并拉动请求#152从csware / syscommand
db8d1bf [斯文STRIC ..] [斯文STRIC ..] Perl中的readline创建空的SYS $命令文件,如果..
753d3d6 [约翰内斯秒。] [约翰内斯秒。]混帐的Windows 1.8.5.2-preview20131230


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 I format the git log output to cut the comment after 50 characters?

I found this in the git-log man page but it will only pad short comments, not cut long ones.

%<(<N>[,trunc|ltrunc|mtrunc]): make the next placeholder take at least N columns,
  padding spaces on the right if necessary. Optionally truncate at the beginning (ltrunc),
  the middle (mtrunc) or the end (trunc) if the output is longer than N columns. Note that
  truncating only works correctly with N >= 2.

解决方案

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

这篇关于如何让git log减少长评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆