Git 是开发者的好帮手,今天跟你们分享的是用 git bisect 来找到你代码中的 bad commit 。
<!-- more -->html
你可能遇到过这种状况, 昨天下班前把模块开发完了, 单元测试验证经过, git commmit
盖上电脑 开开心心下班啦 😄
次日啥上午来了,继续开发,提交了几个 commit ,下午部署了一个版本,发现昨天测试经过的代码出现了 BUG 😂
这个时间你会怎么作, 可能的翻出现 BUG 代码文件的 git log
一翻发现 有20个 commit 🤦
此时你的心情多是崩溃的 🔥 git
告别人肉排查 bad commit 借助 git bisect
找 BUG ✌️segmentfault
git log
命令 找到你肯定代码是 OK 的 git hash 再找到你当前出现 BUG 的 git hashgit bisect start
开始我们的奇妙 debug 之旅 🚀git bisect good 5d5dba7
git bisect bad 692ac39
git bisect bad
git bisect good
git bisect reset
附上操做流程图 api
wujunze@Mac: ~/monkey/code/monkey-api develop $ git bisect start [20:31:46] wujunze@Mac: ~/monkey/code/monkey-api develop $ git logg [20:31:50] wujunze@Mac: ~/monkey/code/monkey-api develop $ git bisect good 16e91a8 [20:31:54] wujunze@Mac: ~/monkey/code/monkey-api develop $ git logg [20:31:59] wujunze@Mac: ~/monkey/code/monkey-api develop $ git bisect bad 692ac39 [20:32:04] Bisecting: 9 revisions left to test after this (roughly 3 steps) [cd1a0814fe21aa3e06020efb5aa4118ead17acce] not filter wujunze@Mac: ~/monkey/code/monkey-api cd1a081 $ git bisect bad [20:32:07] Bisecting: 4 revisions left to test after this (roughly 2 steps) [63bf3176854a4fe112d612cee3f6bacce9e77e7d] fix merge wujunze@Mac: ~/monkey/code/monkey-api 63bf317 $ git bisect good [20:32:11] Bisecting: 2 revisions left to test after this (roughly 1 step) [798239a0397c52127c721b8b84bb430b5fd0e83b] debug wujunze@Mac: ~/monkey/code/monkey-api 798239a $ git bisect bad [20:32:14] Bisecting: 0 revisions left to test after this (roughly 0 steps) [5d5dba7c3fc947768cc609493de9808f3d9cf635] fix assert logic wujunze@Mac: ~/monkey/code/monkey-api 5d5dba7 $ git bisect bad [20:32:23] 5d5dba7c3fc947768cc609493de9808f3d9cf635 is the first bad commit commit 5d5dba7c3fc947768cc609493de9808f3d9cf635 Author: wujunze <itwujunze@163.com> Date: Tue Oct 29 18:20:36 2019 +0800 fix assert logic :040000 040000 b5d77b6ac82d8427d1bc3a9db2213f6c10ea0d63 3f49c18b6569282f7fa2a2c935b9ba73d6d0fbc0 M app wujunze@Mac: ~/monkey/code/monkey-api 5d5dba7 $ git bisect reset [20:32:27] Previous HEAD position was 5d5dba7 fix assert logic Switched to branch 'develop' Your branch is up to date with 'origin/develop'. wujunze@Mac: ~/monkey/code/monkey-api develop $ [20:36:38]
## 百闻不如一 Run 你们能够本身试一下 有什么问题能够在文章下面评论bash
笔者才疏学浅,仓促成文,若有不当之处,还请你们斧正.
本文由 吴钧泽博客 发布!