6 git-bisect - Find the change that introduced a bug by binary search
11 'git bisect' <subcommand> <options>
15 The command takes various subcommands, and different options depending
18 git bisect start [<bad> [<good>...]] [--] [<paths>...]
19 git bisect bad [<rev>]
20 git bisect good [<rev>...]
21 git bisect skip [<rev>...]
22 git bisect reset [<branch>]
24 git bisect replay <logfile>
26 git bisect run <cmd>...
28 This command uses 'git-rev-list --bisect' option to help drive the
29 binary search process to find which change introduced a bug, given an
30 old "good" commit object name and a later "bad" commit object name.
32 Basic bisect commands: start, bad, good
33 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35 The way you use it is:
37 ------------------------------------------------
39 $ git bisect bad # Current version is bad
40 $ git bisect good v2.6.13-rc2 # v2.6.13-rc2 was the last version
41 # tested that was good
42 ------------------------------------------------
44 When you give at least one bad and one good versions, it will bisect
45 the revision tree and say something like:
47 ------------------------------------------------
48 Bisecting: 675 revisions left to test after this
49 ------------------------------------------------
51 and check out the state in the middle. Now, compile that kernel, and
52 boot it. Now, let's say that this booted kernel works fine, then just
55 ------------------------------------------------
56 $ git bisect good # this one is good
57 ------------------------------------------------
61 ------------------------------------------------
62 Bisecting: 337 revisions left to test after this
63 ------------------------------------------------
65 and you continue along, compiling that one, testing it, and depending
66 on whether it is good or bad, you say "git bisect good" or "git bisect
67 bad", and ask for the next bisection.
69 Until you have no more left, and you'll have been left with the first
70 bad kernel rev in "refs/bisect/bad".
75 Oh, and then after you want to reset to the original head, do a
77 ------------------------------------------------
79 ------------------------------------------------
81 to get back to the master branch, instead of being in one of the
82 bisection branches ("git bisect start" will do that for you too,
83 actually: it will reset the bisection state, and before it does that
84 it checks that you're not using some old bisection branch).
89 During the bisection process, you can say
92 $ git bisect visualize
95 to see the currently remaining suspects in `gitk`.
97 Bisect log and bisect replay
98 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100 The good/bad input is logged, and
106 shows what you have done so far. You can truncate its output somewhere
107 and save it in a file, and run
110 $ git bisect replay that-file
113 if you find later you made a mistake telling good/bad about a
116 Avoiding to test a commit
117 ~~~~~~~~~~~~~~~~~~~~~~~~~
119 If in a middle of bisect session, you know what the bisect suggested
120 to try next is not a good one to test (e.g. the change the commit
121 introduces is known not to work in your environment and you know it
122 does not have anything to do with the bug you are chasing), you may
123 want to find a near-by commit and try that instead.
125 It goes something like this:
128 $ git bisect good/bad # previous round was good/bad.
129 Bisecting: 337 revisions left to test after this
130 $ git bisect visualize # oops, that is uninteresting.
131 $ git reset --hard HEAD~3 # try 3 revs before what
135 Then compile and test the one you chose to try. After that, tell
136 bisect what the result was as usual.
141 Instead of choosing by yourself a nearby commit, you may just want git
142 to do it for you using:
145 $ git bisect skip # Current version cannot be tested
148 But computing the commit to test may be slower afterwards and git may
149 eventually not be able to tell the first bad among a bad and one or
150 more "skip"ped commits.
152 Cutting down bisection by giving more parameters to bisect start
153 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155 You can further cut down the number of trials if you know what part of
156 the tree is involved in the problem you are tracking down, by giving
157 paths parameters when you say `bisect start`, like this:
160 $ git bisect start -- arch/i386 include/asm-i386
163 If you know beforehand more than one good commits, you can narrow the
164 bisect space down without doing the whole tree checkout every time you
165 give good commits. You give the bad revision immediately after `start`
166 and then you give all the good revisions you have:
169 $ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --
171 # v2.6.20-rc4 and v2.6.20-rc1 are good
177 If you have a script that can tell if the current source code is good
178 or bad, you can automatically bisect using:
181 $ git bisect run my_script
184 Note that the "run" script (`my_script` in the above example) should
185 exit with code 0 in case the current source code is good and with a
186 code between 1 and 127 (included) in case the current source code is
189 Any other exit code will abort the automatic bisect process. (A
190 program that does "exit(-1)" leaves $? = 255, see exit(3) manual page,
191 the value is chopped with "& 0377".)
193 You may often find that during bisect you want to have near-constant
194 tweaks (e.g., s/#define DEBUG 0/#define DEBUG 1/ in a header file, or
195 "revision that does not have this commit needs this patch applied to
196 work around other problem this bisection is not interested in")
197 applied to the revision being tested.
199 To cope with such a situation, after the inner git-bisect finds the
200 next revision to test, with the "run" script, you can apply that tweak
201 before compiling, run the real test, and after the test decides if the
202 revision (possibly with the needed tweaks) passed the test, rewind the
203 tree to the pristine state. Finally the "run" script can exit with
204 the status of the real test to let "git bisect run" command loop to
209 Written by Linus Torvalds <torvalds@osdl.org>
213 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
217 Part of the gitlink:git[7] suite