使用评论搜索 git 日志

Search git log using a comment

我使用 git log --stat 检查我的 git 日志,其中显示了所有提交以及在这些提交中更改的文件。

现在有一个很久以前的提交,我记得提交消息的一部分,所以当我这样做时 git log --stat | grep 'message text' 日志只显示 'message text'存在。

但是,我至少需要查看提交 ID 以及 grep 结果。我该如何实现?

尝试使用 --oneline :

git log --oneline | grep -F 'message text'

否则,通过 less 传递结果,并使用 less:

进行搜索
git log | less
/message text

尝试使用它来获取完整信息。

git log --all --grep='Your text here'

Git 使用的版本:

git version 2.9.0.windows.1

示例:

$ git log --all --grep='Favourite Module modifie' 

结果:

commit 8226dce6f4f5ffd8143b8aefdee3b9b971040aa0 
Author: Surender Singh <sure**@gmail.com> Date: Thu Aug 25 11:29:32 2016 +0530 
view Favourite Module modified

使用 opts for grep 显示更多上下文行。选择合适大小的num来查看你的id。

grep -A num -B num

这会找到你的评论。

git log --grep "search text" --author your_name

Atlassian Documentation for git log 向下滚动到“通过消息”了解更多详情。

顺便说一句,您可以使用 --author 两次。我需要寻找一组由两个开发人员制作的 check-ins。这是我最喜欢在 git 的大海捞针中寻找那根针的方法。 --pretty=online 做两件事,1) 每个提交都在一行上,以及 2) 显示完整的提交参考号。只需使用 --oneline 就可以给出相同的结果,只是提交参考号被缩写了。

git log --grep "#Bug" --author jones --author smith --pretty=oneline

\dev8.4> git log --grep "#Bug" --author jones --author smith --pretty=oneline
80334597b56add0ad4a3ddd02e7a6514bf01ad1e #Bug -- Further Mods To Code - CC Save
16cc3b4e949e965de9b72eb4583fa8df659528a0 #Bug -- Use new get charge function to load CC.
b207498261b4622ef88cb696365bf9af2f3fc6e1 #Bug -- Reference now editable after CC scan.
56385b7a77e2ec9af3b827f6a9ba93c22f267e51 #Bug -- Reload Entire Page after CC charge.
19e9cb05dabd8cc7c9a80e64187821d562af043c #Bug -- force Guid after save event.
c363ed97fdc2b56d1fcd84ca48eb300dbb120a3d #Bug -- Guid was getting lost in some cases.