1git-bisect(1) 2============= 3 4NAME 5---- 6git-bisect - Find the change that introduced a bug by binary search 7 8 9SYNOPSIS 10-------- 11'git bisect' <subcommand> <options> 12 13DESCRIPTION 14----------- 15The command takes various subcommands, and different options depending 16on the subcommand: 17 18 git bisect start [<paths>...] 19 git bisect bad <rev> 20 git bisect good <rev> 21 git bisect reset [<branch>] 22 git bisect visualize 23 git bisect replay <logfile> 24 git bisect log 25 git bisect run <cmd>... 26 27This command uses 'git-rev-list --bisect' option to help drive the 28binary search process to find which change introduced a bug, given an 29old "good" commit object name and a later "bad" commit object name. 30 31The way you use it is: 32 33------------------------------------------------ 34$ git bisect start 35$ git bisect bad # Current version is bad 36$ git bisect good v2.6.13-rc2 # v2.6.13-rc2 was the last version 37 # tested that was good 38------------------------------------------------ 39 40When you give at least one bad and one good versions, it will bisect 41the revision tree and say something like: 42 43------------------------------------------------ 44Bisecting: 675 revisions left to test after this 45------------------------------------------------ 46 47and check out the state in the middle. Now, compile that kernel, and 48boot it. Now, let's say that this booted kernel works fine, then just 49do 50 51------------------------------------------------ 52$ git bisect good # this one is good 53------------------------------------------------ 54 55which will now say 56 57------------------------------------------------ 58Bisecting: 337 revisions left to test after this 59------------------------------------------------ 60 61and you continue along, compiling that one, testing it, and depending 62on whether it is good or bad, you say "git bisect good" or "git bisect 63bad", and ask for the next bisection. 64 65Until you have no more left, and you'll have been left with the first 66bad kernel rev in "refs/bisect/bad". 67 68Oh, and then after you want to reset to the original head, do a 69 70------------------------------------------------ 71$ git bisect reset 72------------------------------------------------ 73 74to get back to the master branch, instead of being in one of the 75bisection branches ("git bisect start" will do that for you too, 76actually: it will reset the bisection state, and before it does that 77it checks that you're not using some old bisection branch). 78 79During the bisection process, you can say 80 81------------ 82$ git bisect visualize 83------------ 84 85to see the currently remaining suspects in `gitk`. 86 87The good/bad input is logged, and 88 89------------ 90$ git bisect log 91------------ 92 93shows what you have done so far. You can truncate its output somewhere 94and save it in a file, and run 95 96------------ 97$ git bisect replay that-file 98------------ 99 100if you find later you made a mistake telling good/bad about a 101revision. 102 103If in a middle of bisect session, you know what the bisect suggested 104to try next is not a good one to test (e.g. the change the commit 105introduces is known not to work in your environment and you know it 106does not have anything to do with the bug you are chasing), you may 107want to find a near-by commit and try that instead. 108 109It goes something like this: 110 111------------ 112$ git bisect good/bad # previous round was good/bad. 113Bisecting: 337 revisions left to test after this 114$ git bisect visualize # oops, that is uninteresting. 115$ git reset --hard HEAD~3 # try 3 revs before what 116 # was suggested 117------------ 118 119Then compile and test the one you chose to try. After that, tell 120bisect what the result was as usual. 121 122You can further cut down the number of trials if you know what part of 123the tree is involved in the problem you are tracking down, by giving 124paths parameters when you say `bisect start`, like this: 125 126------------ 127$ git bisect start arch/i386 include/asm-i386 128------------ 129 130If you have a script that can tell if the current source code is good 131or bad, you can automatically bisect using: 132 133------------ 134$ git bisect run my_script 135------------ 136 137Note that the "run" script (`my_script` in the above example) should 138exit with code 0 in case the current source code is good and with a 139code between 1 and 127 (included) in case the current source code is 140bad. 141 142Any other exit code will abort the automatic bisect process. (A 143program that does "exit(-1)" leaves $? = 255, see exit(3) manual page, 144the value is chopped with "& 0377".) 145 146You may often find that during bisect you want to have near-constant 147tweaks (e.g., s/#define DEBUG 0/#define DEBUG 1/ in a header file, or 148"revision that does not have this commit needs this patch applied to 149work around other problem this bisection is not interested in") 150applied to the revision being tested. 151 152To cope with such a situation, after the inner git-bisect finds the 153next revision to test, with the "run" script, you can apply that tweak 154before compiling, run the real test, and after the test decides if the 155revision (possibly with the needed tweaks) passed the test, rewind the 156tree to the pristine state. Finally the "run" script can exit with 157the status of the real test to let "git bisect run" command loop to 158know the outcome. 159 160Author 161------ 162Written by Linus Torvalds <torvalds@osdl.org> 163 164Documentation 165------------- 166Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. 167 168GIT 169--- 170Part of the gitlink:git[7] suite 171