我有一个 git log 别名,它将每个提交打印为一行。由于有些人在提交日志中写了太长的一行,许多提交换行。如何格式化 git log 输出以在 50 个字符后剪切注释?
我在 git-log 手册页中找到了这个,但它只会填充简短的注释,不会剪切长的注释。
%<(<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.
最佳答案
文档中并不清楚需要哪些字符,但以下示例将主题行削减为 50 个字符:
git log --oneline --format="%h %<(50,trunc)%s"
格式规范为%<
并且该参数需要放在括号中。在这种情况下,50 个字符并截断多余部分。
例如,在 msysGit 存储库上执行此操作会产生:
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 - 如何让 git log 剪切长注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21830810/