"More content" git 日志中提交消息的指示器 --online?

"More content" indicator for commit messages in git log --online?

如果您在 Github 中查看提交历史记录,例如,它将使用省略号指示提交消息在其主题行之外还有其他内容行:

使用时:

git log --oneline

在终端中,有没有办法得到类似的"more content"指标?

--oneline 是一种标准(而且非常方便)的快捷方式格式,但对于任何更具体的内容,您可以依赖 --pretty 并构建您的输出。

试试这个漂亮的格式 (doc)

git log --pretty=format:"%h %d %s %<(1,trunc)%b"

%h 用于短格式哈希
%d 用于装饰(分支、标签和 HEAD
%s 为主题
%<(1,trunc) 会将正文 (%b) 截断为 ...(如果有的话)。


着色

如果不想失去--oneline的自动着色,可以用%C(<color>)复制大部分(doc)

git log --pretty=format:"%C(yellow)%h %C(auto)%d %C(reset)%s %C(red)%<(1,trunc)%b"

别名

当然有这样的格式,因为没有人愿意每次都输入它,所以几乎必须将其设为别名

git config --global alias.line 'git log --pretty=format:"%C(yellow)%h %C(red)%d %C(reset)%s %C(red)%<(1,trunc)%b"'

# which combines well with most options
git line
git line -10
git line --all --graph

(最后,您还可以将 -10 或任何其他值作为快捷方式中的默认值,除非您明确覆盖它,否则它将被使用,非常方便)