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