Git 是開發者的好幫手,今天跟你們分享的是用 git bisect 來找到你代碼中的 bad commit 。html
<!-- more -->git
你可能遇到過這種狀況, 昨天下班前把模塊開發完了, 單元測試驗證經過, git commmit
蓋上電腦 開開心心下班啦 😄
次日啥上午來了,繼續開發,提交了幾個 commit ,下午部署了一個版本,發現昨天測試經過的代碼出現了 BUG 😂
這個時間你會怎麼作, 可能的翻出現 BUG 代碼文件的 git log
一翻發現 有20個 commit 🤦
此時你的心情多是崩潰的 🔥api
告別人肉排查 bad commit 藉助 git bisect
找 BUG ✌️bash
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
附上操做流程圖 app
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]
筆者才疏學淺,倉促成文,若有不當之處,還請你們斧正.單元測試
本文由 吳鈞澤博客 發佈!測試