在git日志的每一行中打印sha

在git日志的每一行中打印sha,git,Git,我正在寻找一种以这种格式打印git日志的方法: # sha subject: body 8c75408 commit a: this is a first line of commit a 8c75408 commit a: this is a second line of commit a 5b710e0 commit b: this is a first line of commit b c59982e commit c: this is a first line of commit c

我正在寻找一种以这种格式打印git日志的方法:

# sha subject: body
8c75408 commit a: this is a first line of commit a
8c75408 commit a: this is a second line of commit a
5b710e0 commit b: this is a first line of commit b
c59982e commit c: this is a first line of commit c
您可能会注意到,这是一种非常类似于
grep的格式,文件名为

也就是说,它打印所有带有前缀sha(或其他格式化字符串)的提交注释,这样我就可以使用
| grep“second line”
轻松地grep注释中的特定行。比如说,

# after grep
8c75408 commit a: this is a second line of commit a
一些可能的选择是:

  • git log--format='%h%s'--grep'second line'
    与我想要的最为相似,只是它不打印匹配的实际行

    # output
    8c75408 commit a
    
  • git日志--格式='%h%s:%n%b'--grep“第二行”
    打印匹配提交的所有提交消息

    # output
    8c75408 commit a:
    this is a first line of commit a
    this is a second line of commit a
    

我的
.gitconfig
中有一个别名

[alias]

    lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
[别名]
lg=log--color--graph--pretty=格式:'%Cred%h%Creset-%C(黄色)%d%Creset%s%Cgreen(%cr)%C(粗体蓝色)%Creset'--abbrev提交
在meld的存储库上运行一个
git lg
,会得到以下输出:


如果这是您想要的,我也建议使用GUI,
gitk
是一个不错的选择。

OP希望显示完整的提交消息,每一行都由提交散列注释。@poke哦,我没有看到。。。很抱歉