译者注:按照二分查找算法,bisect 根据你标记的结果,决定是检出左半边的中间提交点(如果你标记为 bad)还是右半边的中间提交点(如果你标记为 good)
在 bisect 新检出的提交点上,我们再次运行测试命令。这次依然是个好的提交点。
$ grep 1013 file.txt
$ git bisect good
Bisecting:剩余 127 个修订待测试 (大概还需要 7 步)
[4a4a668bf3363d09af5fd1906bc4272aacdb4495] added 896
再次检测,还是好的提交点。
$ grep 1013 file.txt
$ git bisect good
Bisecting: 剩余 63 个修订待测试 (大概还需要 6 步)
[9059c5b8b898159e8d1d797bff3b1febd1fd6a1c] added 960
让我们看看这些消息:除了告诉你当前新检出的提交点以及新的搜索范围内有多少个待测试的提交点外,它还估计出你最多还需要重复多少次测试命令就能找到你要的提交点。这次又是一个好的提交点。
$ grep 1013 file.txt
$ git bisect good
Bisecting: 剩余 31 个修订待测试 (大概还需要 5 步)
[0c844d0b33ef297b742206ebc293f4925705b083] added 992
继续,依然是一个好的提交点。
$ grep 1013 file.txt
$ git bisect good
Bisecting: 剩余 15 个修订待测试 (大概还需要 4 步)
[0ee17eb17bd96b321a01c73eb13a8929a68b1239] added 1008
还有 4 步,这次依然 good。
$ grep 1013 file.txt
$ git bisect good
Bisecting: 剩余 7 个修订待测试 (大概还需要 3 步)
[dfb1e71736dcfffa2a30aecd7299f45f757c057e] added 1016
这次测试命令终于有了输出,bug 现身了!我们把这个提交点标记为坏的。
$ grep 1013 file.txt
1013
$ git bisect bad
Bisecting: 剩余 3 个修订待测试 (大概还需要 2 步)
[6e6d08c374df5162fed65fed82859b69f86b936e] added 1012
终点近在咫尺,测试通过,我们把它标记为好的。
$ grep 1013 file.txt
$ git bisect bad
Bisecting: 剩余 1 个修订待测试 (大概还需要 1 步)
254efa859d7fc66f1f58a59f0] added 1014
坏的提交点。
$ grep 1013 file.txt
1013
$ git bisect bad
Bisecting: 剩余 0 个修订待测试 (大概还需要 0 步)
8e16d98ec7039a7c53855dd9ed6] added 1013
最后一步,这次是坏的。
$ git bisect bad 458eab0eb8d808e16d98ec7039a7c53855dd9ed6 is the first bad commit commit 458eab0eb8d808e16d98ec7039a7c53855dd9ed6 Author: Rodrigo Flores <mail@rodrigoflores.org> Date: Tue Oct 21 22:31:05 2014 -0200 added 1013 :100644 100644 7bc3db7f48a43ccf1a8cc7c26146912cc88c1009 b393a2138a96c1530f41f70 1ab43cca893226976 M file.txt我们终于得到了那个引入 1013 数字的提交点。命令 git bisect log 可以回放整个过程。
$ git bisect start # bad: [740cdf012013dc41a39b41d4b09b57a970bfe38f] added 1024 git bisect bad 740cdf012013dc41a39b41d4b09b57a970bfe38f # good: [7c0dcfa7514379151e0d83ffbf805850d2093538] added 1 git bisect good 7c0dcfa7514379151e0d83ffbf805850d2093538 # good: [8950f7db7e7cad0b2dc394ff9b75fc3d38c9d72a] added 512 git bisect good 8950f7db7e7cad0b2dc394ff9b75fc3d38c9d72a # good: [a01ba83f3500b48da97c5f5c33052623aaa4161a] added 768 git bisect good a01ba83f3500b48da97c5f5c33052623aaa4161a # good: [4a4a668bf3363d09af5fd1906bc4272aacdb4495] added 896 git bisect good 4a4a668bf3363d09af5fd1906bc4272aacdb4495 # good: [9059c5b8b898159e8d1d797bff3b1febd1fd6a1c] added 960 git bisect good 9059c5b8b898159e8d1d797bff3b1febd1fd6a1c # good: [0c844d0b33ef297b742206ebc293f4925705b083] added 992 git bisect good 0c844d0b33ef297b742206ebc293f4925705b083 # good: [0ee17eb17bd96b321a01c73eb13a8929a68b1239] added 1008 git bisect good 0ee17eb17bd96b321a01c73eb13a8929a68b1239 # bad: [dfb1e71736dcfffa2a30aecd7299f45f757c057e] added 1016 git bisect bad dfb1e71736dcfffa2a30aecd7299f45f757c057e # good: [6e6d08c374df5162fed65fed82859b69f86b936e] added 1012 git bisect good 6e6d08c374df5162fed65fed82859b69f86b936e # bad: [1d23b7045a8accd254efa859d7fc66f1f58a59f0] added 1014 git bisect bad 1d23b7045a8accd254efa859d7fc66f1f58a59f0 # bad: [458eab0eb8d808e16d98ec7039a7c53855dd9ed6] added 1013 git bisect bad 458eab0eb8d808e16d98ec7039a7c53855dd9ed6 # first bad commit: [458eab0eb8d808e16d98ec7039a7c53855dd9ed6] added 1013