当你疯狂coding,不停地提交代码,干得酣畅淋漓的时候,测试人员告诉你,不好意思你所有的feature都没有办法测试,因为最新的几个包都 没有办法工作,你愤怒那,咆哮那,冲到命令行下,运指如飞的敲下命令git log,试图发现究竟是哪个混蛋干得,结果你发现其它的疯子在你提交的时候,也卖力的提交那50,60次,然后你沉默那,你石化那,你陷入哀伤不能自拔。 这个时候,你需要的就是git bisect命令
git log --pretty=oneline 4d1ea14a2233c3aa330ee5a76ce990e4b920d0c5 Merge branch 'W1134' of 10.120.10.101:/home/ckt/work/catch_cd into W1134 5e4091d7a4a93f1145b5c6045831b242fd0f8e0a [Type] Bug Fix a76f09620871b34024f6bd6226493ae4a95f5c80 This reverts commit 9083531e58a8445498a1df70e81fa9383e47113d. It seems after change the files related to IPO the cel 7cee00c217111f5ecf6cc661cb45c17c037d6113 Merge branch 'W1134' of 10.120.10.101:/home/ckt/work/catch_cd into W1134 408d8bc68e404abe62e03cd965c6f48047e3af71 [Type] Bug Fix 70f48149afeac31482aedce98eda7f6a29f9b891 [Type] Bug Fix 737b66e802c1b706f284b83d285b00f809413d8e [Type] Bug Fix 9594ec81850ad6c77daa47043bde59a569f48ab8 Merge branch 'W1134' of 10.120.10.101:/home/ckt/work/catch_cd into W1134 9083531e58a8445498a1df70e81fa9383e47113d [Type] Bug Fix 4389f1eae9eff9fe6ee057676af04366c20ac197 [Type] Bug Fix a9721f609a754d407fdc990f35156ac14ef4a4c4 [Type] Bug Fix 3a77bdde643cd6d0749b5eb2022cd86215097a8b [Type] Bug Fix 9abfe752886979180322890ff7c8014ddaee1d67 Merge branch 'W1134' of 10.120.10.101:/home/ckt/work/catch_cd into W1134 adf655d6423ef503be4f69dfb41151a5b1aaac04 [Type] Bug Fix e774992695326d196fd2e00b4cc30e1756f82442 [Type] Bug Fix 4fce5febbc72806be19cf7c4707b042b12c9fdf1 [Type] Bug Fix daf9c58d2e38a91ea38d12f6f30ede565869d47f Merge branch 'W1134' of 10.120.10.101:/home/ckt/work/catch_cd into W1134 6e24ab2f2dbfcf7a76774c32e8a9e2ca9e3be9be [Type] 1169f57da567bababed5f666a1ce19fcac49e846 Merge branch 'W1134' of 10.120.10.101:/home/ckt/work/catch_cd into W1134 2705e6918260d993a68d5175b42238022686cd80 [Type] Bug Fix 3e1bb3974cfcd284e49bdbcc68953336761d2723 Chinese Format to insert fixed bug482 f7acd9f58b14885c1c6d4df4497d20b651cb5f36 Merge branch 'W1134' of 10.120.10.101:/home/ckt/work/catch_cd into W1134 2642184ac6c0be4a10bd405a59f005321ca75286 To keep only one memsicd process in system. -- Gou Runqiang 578dfeae63f38d65a59328bdd7ba5ff6eccb1a0a Merge branch 'W1134' of 10.120.10.101:/home/ckt/work/catch_cd into W1134 5ab3a6b447a05278cd41b1cd52d78f59e3abb5b3 [Type] Bug Fix
使用方法
要干的事情其实很简单,就是逐个排查commit,发现罪魁祸首!逐个排查,是一件很闹心的事情,比如我有100多个commit,岂不是要做100多次, 要死人的哦。还好二分法出场,是的无所不在的算法,git bisect利用二分法,高效帮您找到问题所在。
我们开始吧:
1.看一下我们的历史
$ git log --pretty=oneline 11916c10051e13c27055228c122e36a22191d0a7 add iomanip 246e1926361b6fe157d82820af332043533ab243 fix bugs 1235436rertrb6fe157d82820af332043533ab243 add new feature deaea5e6f1d0aab171d1dc82055e226182b92695 add main.cc
假设deaea5e6f1d0aab171d1dc82055e226182b92695 是好的,11916c10051e13c27055228c122e36a22191d0a7 系统crash
2.开启bisect魔法工具
$git bisect start $git bisect good deaea5e6f1d0aab171d1dc82055e226182b92695 $git bisect bad 11916c10051e13c27055228c122e36a22191d0a7
系统将制动帮你把rev变到位于good和bad两个commit提交历史中间的一个commit 246e1926361b6fe157d82820af332043533ab243,然后你就make打包测试,验证这个commit是不是祸水
3.继续验证commit
- 假设246e1926361b6fe157d82820af332043533ab243仍然是坏的,那么执行
$git bisect bad
版本将切换到位于原始设置的good和最新的bad之间的commit,你再make打包测试,验证这个commit是不是祸水,如此反复,直到回 溯到真正引起问题的那个commit,然后你就可以跳到那个倒霉的committer面前,斥责他,殴打TA,但请不要忘记,那个倒霉蛋也可能就是你自 己。
4.结束查找
- 你揪出那祸水,打完收工,表忘记结束bisect,否则你会郁闷地发现,你最近的工作都不见那,因为你正处在一个过去的rev里面
$git bisect reset