如果发现当前branch的代码有问题,而不知道在什么时间被人改坏了,可以用git bisect进行二分查找,快速定位问题。
比如我们在common/payment.class.php这个文件中有一行代码

curl_setopt ($ch, CURLOPT_TIMEOUT, 15);

被奇怪的删除掉了,也不知道删除它的原因是什么, 只知道在2018-12-06的某个版本 rev=29b40048e41 时代码是包含这1行的。
因此可以简单的用git bisect定位是谁做出删除修改的:

git bisect start

git bisect  good 29b40048e41
git bisect bad HEAD
git bisect run  grep 'CURLOPT_TIMEOUT, 15' common/payment.class.php

简单等待几秒钟, 修改的commit就找到了,相当黑科技:

running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
Bisecting: 4859 revisions left to test after this (roughly 12 steps)
[204bf3a98ca58c6df72f89ef9f9c0ef67761080b] maint:@lixuan 906-新手任务-接口格式
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
Bisecting: 2429 revisions left to test after this (roughly 11 steps)
[10c9d05322fb7e945e189cae9d094baa24eb3371] maint:@dengxiaochao 关注关系redis切库
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
Bisecting: 1214 revisions left to test after this (roughly 10 steps)
[221ff56686d1839b68b5be5d725ea5f6dc36ac31] MAINT: fix 高分榜翻页page@dengxiaochao
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
Bisecting: 606 revisions left to test after this (roughly 9 steps)
[779847710f9cfa729a9714ed1d1ee8cdbb4d2a70] maint:push后台-兼容老后台,不用测  @Yuanchangjun
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
        curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
Bisecting: 303 revisions left to test after this (roughly 8 steps)
[f044ded3dd8bac233927bfc94b4a2079575ae605] maint: 钱包数据库du xie账号配置 不用测试 @zhouhui
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
        curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
Bisecting: 151 revisions left to test after this (roughly 7 steps)
[1f65e6403afda43a8490087d855dcd13aebe8d95] MAINT: 添加支付宝sdk,不用测试@wangsanchao
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
        curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
Bisecting: 75 revisions left to test after this (roughly 6 steps)
[9be1623fcd6b01543a7bbd4588111c9799a4ae64] maint:钱包修改生成财务打款记录 不用测试 @zhouhui
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
        curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
Bisecting: 37 revisions left to test after this (roughly 5 steps)
[8e14a6349e87b5cfbc1377c9490c7aa3b05e222d] maint: 钱包相关 财务后台 不用测试 @zhouhui
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
Bisecting: 18 revisions left to test after this (roughly 4 steps)
[4c531389bfcce12ba3ea051983f0fb98b3d87085] MAINT: 高分榜一审@yumingkun
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
        curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
Bisecting: 9 revisions left to test after this (roughly 3 steps)
[83d2badcd475c9524483ad6ffa66427442af6676] maint:钱包相关 后台打款明细添加按userid查询字段 不用测试 @zhouhui
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
Bisecting: 4 revisions left to test after this (roughly 2 steps)
[ab555514ca0dd18e74bdd4432e36e18d8dba2afe] maint:@lixuan 任务中心-完善日志
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
        curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
Bisecting: 2 revisions left to test after this (roughly 1 step)
[05a2a5c5c8f2b84fa8a12d458bdbe904e862a0e6] MAINT:回退之前的修改,校验超时设置15秒长还是会有问题,看日志苹果会超时抽风 不用测 @liusurong
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[6404ea9662090469f77a46886614bc1582ea1fe6] maint:@lixuan 紧急fix bug 任务中心-完成明日再来任务,会漏发做完全部新手任务的奖励
running grep CURLOPT_TIMEOUT, 15 common/payment.class.php
        curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
05a2a5c5c8f2b84fa8a12d458bdbe904e862a0e6 is the first bad commit
commit 05a2a5c5c8f2b84fa8a12d458bdbe904e862a0e6
Author: liusurong <liusurong@bbcd940b-3153-4649-9eaf-8d73ff426239>
Date:   Wed Jan 16 02:32:48 2019 +0000

    MAINT:回退之前的修改,校验超时设置15秒长还是会有问题,看日志苹果会超时抽风 不用测 @liusurong
    

:040000 040000 bf91e2ad602db0b551452bc6536e7ed39bcb602d 526200888c2c21194cdaaf0bd430950e836d15f5 M    common
bisect run success

标签: none

添加新评论