git - 如何让 git log 剪切长注释?

标签 git

我有一个 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/

相关文章:

具有多个帐户的 Git 在执行 ssh 时提供相同的用户名

git pull *after* git rebase?

git - 有没有办法每次都通过 web 界面手动上传差异来使用带有 git 的审查板?

git - 将 master merge 到 branch 和将 branch merge 到 master 有什么区别?

git - 为什么Git的单键设置不起作用?

git - 使用 $GIT_DIR 环境变量或 --git-dir 标志在同一目录中运行多个 git 存储库是一个坏主意吗?

git - 如何管理 git 存储库中的 IDE 文件?

eclipse - Egit 在提交后上演?

git - 如何阻止 Git 中某些特定类型的文件提交?

git - 如何在 GitHub 上添加我的整个项目?