【开发工具】【git】通过关键字搜索对应的git提交日志

因为想查看某一个函数对应在源码中的修改记录,就想到了git log.试试看能不能搜索到相关信息。

想找到一个内核函数相关的git log修改记录,第一想法是"git log + grep"操作:

zhugeyifan@83-28:~/source/linux-stable/linux-stable$ git log | grep interruptible_sleep_on
    swim3: fix interruptible_sleep_on race
    interruptible_sleep_on is racy and going away. This replaces the one
    The interruptible_sleep_on_timeout in DAC960_gam_ioctl seems equivalent
    interruptible_sleep_on is racy and going away. In the arv driver that
    parport: fix interruptible_sleep_on race
    The interruptible_sleep_on function is can still lead to the
    [hans.verkuil@cisco.com: replaced interruptible_sleep_on_timeout by
    [media] radio-cadet: avoid interruptible_sleep_on race
    ...

搜索出来的信息非常的零散,无法去查看具体的某一个提交记录等。

这样并没有什么用...还有没有什么办法?


按提交信息检索

后来找到一个好的办法:

git log --grep=xxx

按提交信息来过滤提交,你可以使用 --grep 标记。

它会搜索git log中的提交信息,并将匹配上的信息整段git log显示出来,非常的方便!

实例:

比如说,我现在需要搜索内核代码中的interruptible_sleep_on的提交记录,我就可以用下面这个命令来显示这个 interruptible_sleep_on相关的所有提交:

zhugeyifan@83-28:~/source/linux-stable/linux-stable$ git log --grep=interruptible_sleep_on
commit 106fd892bc714a9b7c28daba98a3623a41c32f1a
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Wed Feb 26 12:01:44 2014 +0100

    swim3: fix interruptible_sleep_on race
    
    interruptible_sleep_on is racy and going away. This replaces the one
    caller in the swim3 driver with the equivalent race-free
    wait_event_interruptible call. Since we're here already, this
    also fixes the case where we get interrupted from atomic context,
    which used to just spin in the loop.
    
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Cc: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Jens Axboe <axboe@fb.com>

commit 9c552e1ddd3658944787d75d90a42e1a2b74b7ea
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Wed Feb 26 12:01:43 2014 +0100

    DAC960: remove sleep_on usage
    
    
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Cc: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Jens Axboe <axboe@fb.com>

commit 9c552e1ddd3658944787d75d90a42e1a2b74b7ea
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Wed Feb 26 12:01:43 2014 +0100

    DAC960: remove sleep_on usage
    
    sleep_on and its variants are going away. The use of sleep_on() in
    DAC960_V2_ExecuteUserCommand seems to be bogus because the command
    by the time we get there, the command has completed already and
    we just enter the timeout. Based on this interpretation, I concluded
    that we can replace it with a simple msleep(1000) and rearrange the
    code around it slightly.
    
    The interruptible_sleep_on_timeout in DAC960_gam_ioctl seems equivalent
    to the race-free version using wait_event_interruptible_timeout.
    I left the driver to return -EINTR rather than -ERESTARTSYS to preserve
    the timeout behavior.
    
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Cc: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Jens Axboe <axboe@fb.com>
...

这些内容相比之前的信息,真的充实了很多!


当然,git中还有很多类似的搜索“关键字”的命令

按作者进行搜索:

当你只想看某一特定作者的提交的时候,你可以使用 --author 标记。它接受正则表达式,返回所有作者名字满足这个规则的提交。如果你知道那个作者的确切名字你可以直接传入文本字符串:

git log --author="John"

按文件进行搜索:

很多时候,你只对某个特定文件的更改感兴趣。为了显示某个特定文件的历史,你只需要传入文件路径。比如说,下面这个命令返回所有和 foo.py 和 bar.py 文件相关的提交:

git log -- foo.py bar.py

按范围进行搜索:

你可以传入范围来筛选提交。这个范围由下面这样的格式指定,其中 <since> 和 <until>是提交的引用:

git log <since>..<until>

参考朝西的生活:https://www.jianshu.com/p/f2fa0a590370

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Evan_ZGYF丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值