Autogenerated HTML docs for v1.7.1-rc0-27-g3b0c
[git/jnareb-git.git] / git-bisect.html
blob93bafeeddc80e8e1df36a02b62ea51d15b989500
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <meta name="generator" content="AsciiDoc 8.2.5" />
7 <style type="text/css">
8 /* Debug borders */
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11 border: 1px solid red;
15 body {
16 margin: 1em 5% 1em 5%;
19 a {
20 color: blue;
21 text-decoration: underline;
23 a:visited {
24 color: fuchsia;
27 em {
28 font-style: italic;
31 strong {
32 font-weight: bold;
35 tt {
36 color: navy;
39 h1, h2, h3, h4, h5, h6 {
40 color: #527bbd;
41 font-family: sans-serif;
42 margin-top: 1.2em;
43 margin-bottom: 0.5em;
44 line-height: 1.3;
47 h1, h2, h3 {
48 border-bottom: 2px solid silver;
50 h2 {
51 padding-top: 0.5em;
53 h3 {
54 float: left;
56 h3 + * {
57 clear: left;
60 div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
65 hr {
66 border: 1px solid silver;
69 p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
74 pre {
75 padding: 0;
76 margin: 0;
79 span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
83 font-size: 1.1em;
85 span#email {
87 span#revision {
88 font-family: sans-serif;
91 div#footer {
92 font-family: sans-serif;
93 font-size: small;
94 border-top: 2px solid silver;
95 padding-top: 0.5em;
96 margin-top: 4.0em;
98 div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
102 div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
107 div#preamble,
108 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110 div.admonitionblock {
111 margin-right: 10%;
112 margin-top: 1.5em;
113 margin-bottom: 1.5em;
115 div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
120 div.content { /* Block element content. */
121 padding: 0;
124 /* Block element titles. */
125 div.title, caption.title {
126 font-family: sans-serif;
127 font-weight: bold;
128 text-align: left;
129 margin-top: 1.0em;
130 margin-bottom: 0.5em;
132 div.title + * {
133 margin-top: 0;
136 td div.title:first-child {
137 margin-top: 0.0em;
139 div.content div.title:first-child {
140 margin-top: 0.0em;
142 div.content + div.title {
143 margin-top: 0.0em;
146 div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
152 div.listingblock {
153 margin-right: 0%;
155 div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
161 div.quoteblock > div.content {
162 padding-left: 2.0em;
165 div.attribution {
166 text-align: right;
168 div.verseblock + div.attribution {
169 text-align: left;
172 div.admonitionblock .icon {
173 vertical-align: top;
174 font-size: 1.1em;
175 font-weight: bold;
176 text-decoration: underline;
177 color: #527bbd;
178 padding-right: 0.5em;
180 div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
185 div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
190 div.verseblock div.content {
191 white-space: pre;
194 div.imageblock div.content { padding-left: 0; }
195 div.imageblock img { border: 1px solid silver; }
196 span.image img { border-style: none; }
198 dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
202 dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
207 dd > *:first-child {
208 margin-top: 0;
211 ul, ol {
212 list-style-position: outside;
214 div.olist2 ol {
215 list-style-type: lower-alpha;
218 div.tableblock > table {
219 border: 3px solid #527bbd;
221 thead {
222 font-family: sans-serif;
223 font-weight: bold;
225 tfoot {
226 font-weight: bold;
229 div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
233 div.hlist td {
234 padding-bottom: 5px;
236 td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
241 td.hlist2 {
242 vertical-align: top;
245 @media print {
246 div#footer-badges { display: none; }
249 div#toctitle {
250 color: #527bbd;
251 font-family: sans-serif;
252 font-size: 1.1em;
253 font-weight: bold;
254 margin-top: 1.0em;
255 margin-bottom: 0.1em;
258 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
262 div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
266 div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
270 div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
274 include1::./stylesheets/xhtml11-manpage.css[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div.sidebar-content {
278 background: #ffffee;
279 border: 1px solid silver;
280 padding: 0.5em;
282 div.sidebar-title, div.image-title {
283 font-family: sans-serif;
284 font-weight: bold;
285 margin-top: 0.0em;
286 margin-bottom: 0.5em;
289 div.listingblock div.content {
290 border: 1px solid silver;
291 background: #f4f4f4;
292 padding: 0.5em;
295 div.quoteblock-content {
296 padding-left: 2.0em;
299 div.exampleblock-content {
300 border-left: 2px solid silver;
301 padding-left: 0.5em;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc a:visited { color: blue; }
306 </style>
307 <title>git-bisect(1)</title>
308 </head>
309 <body>
310 <div id="header">
311 <h1>
312 git-bisect(1) Manual Page
313 </h1>
314 <h2>NAME</h2>
315 <div class="sectionbody">
316 <p>git-bisect -
317 Find by binary search the change that introduced a bug
318 </p>
319 </div>
320 </div>
321 <h2>SYNOPSIS</h2>
322 <div class="sectionbody">
323 <div class="para"><p><em>git bisect</em> &lt;subcommand&gt; &lt;options&gt;</p></div>
324 </div>
325 <h2 id="_description">DESCRIPTION</h2>
326 <div class="sectionbody">
327 <div class="para"><p>The command takes various subcommands, and different options depending
328 on the subcommand:</p></div>
329 <div class="literalblock">
330 <div class="content">
331 <pre><tt>git bisect help
332 git bisect start [&lt;bad&gt; [&lt;good&gt;...]] [--] [&lt;paths&gt;...]
333 git bisect bad [&lt;rev&gt;]
334 git bisect good [&lt;rev&gt;...]
335 git bisect skip [(&lt;rev&gt;|&lt;range&gt;)...]
336 git bisect reset [&lt;commit&gt;]
337 git bisect visualize
338 git bisect replay &lt;logfile&gt;
339 git bisect log
340 git bisect run &lt;cmd&gt;...</tt></pre>
341 </div></div>
342 <div class="para"><p>This command uses <em>git rev-list --bisect</em> to help drive the
343 binary search process to find which change introduced a bug, given an
344 old "good" commit object name and a later "bad" commit object name.</p></div>
345 <h3 id="_getting_help">Getting help</h3><div style="clear:left"></div>
346 <div class="para"><p>Use "git bisect" to get a short usage description, and "git bisect
347 help" or "git bisect -h" to get a long usage description.</p></div>
348 <h3 id="_basic_bisect_commands_start_bad_good">Basic bisect commands: start, bad, good</h3><div style="clear:left"></div>
349 <div class="para"><p>Using the Linux kernel tree as an example, basic use of the bisect
350 command is as follows:</p></div>
351 <div class="listingblock">
352 <div class="content">
353 <pre><tt>$ git bisect start
354 $ git bisect bad # Current version is bad
355 $ git bisect good v2.6.13-rc2 # v2.6.13-rc2 was the last version
356 # tested that was good</tt></pre>
357 </div></div>
358 <div class="para"><p>When you have specified at least one bad and one good version, the
359 command bisects the revision tree and outputs something similar to
360 the following:</p></div>
361 <div class="listingblock">
362 <div class="content">
363 <pre><tt>Bisecting: 675 revisions left to test after this</tt></pre>
364 </div></div>
365 <div class="para"><p>The state in the middle of the set of revisions is then checked out.
366 You would now compile that kernel and boot it. If the booted kernel
367 works correctly, you would then issue the following command:</p></div>
368 <div class="listingblock">
369 <div class="content">
370 <pre><tt>$ git bisect good # this one is good</tt></pre>
371 </div></div>
372 <div class="para"><p>The output of this command would be something similar to the following:</p></div>
373 <div class="listingblock">
374 <div class="content">
375 <pre><tt>Bisecting: 337 revisions left to test after this</tt></pre>
376 </div></div>
377 <div class="para"><p>You keep repeating this process, compiling the tree, testing it, and
378 depending on whether it is good or bad issuing the command "git bisect good"
379 or "git bisect bad" to ask for the next bisection.</p></div>
380 <div class="para"><p>Eventually there will be no more revisions left to bisect, and you
381 will have been left with the first bad kernel revision in "refs/bisect/bad".</p></div>
382 <h3 id="_bisect_reset">Bisect reset</h3><div style="clear:left"></div>
383 <div class="para"><p>After a bisect session, to clean up the bisection state and return to
384 the original HEAD, issue the following command:</p></div>
385 <div class="listingblock">
386 <div class="content">
387 <pre><tt>$ git bisect reset</tt></pre>
388 </div></div>
389 <div class="para"><p>By default, this will return your tree to the commit that was checked
390 out before <tt>git bisect start</tt>. (A new <tt>git bisect start</tt> will also do
391 that, as it cleans up the old bisection state.)</p></div>
392 <div class="para"><p>With an optional argument, you can return to a different commit
393 instead:</p></div>
394 <div class="listingblock">
395 <div class="content">
396 <pre><tt>$ git bisect reset &lt;commit&gt;</tt></pre>
397 </div></div>
398 <div class="para"><p>For example, <tt>git bisect reset HEAD</tt> will leave you on the current
399 bisection commit and avoid switching commits at all, while <tt>git bisect
400 reset bisect/bad</tt> will check out the first bad revision.</p></div>
401 <h3 id="_bisect_visualize">Bisect visualize</h3><div style="clear:left"></div>
402 <div class="para"><p>To see the currently remaining suspects in <em>gitk</em>, issue the following
403 command during the bisection process:</p></div>
404 <div class="listingblock">
405 <div class="content">
406 <pre><tt>$ git bisect visualize</tt></pre>
407 </div></div>
408 <div class="para"><p><tt>view</tt> may also be used as a synonym for <tt>visualize</tt>.</p></div>
409 <div class="para"><p>If the <em>DISPLAY</em> environment variable is not set, <em>git log</em> is used
410 instead. You can also give command line options such as <tt>-p</tt> and
411 <tt>--stat</tt>.</p></div>
412 <div class="listingblock">
413 <div class="content">
414 <pre><tt>$ git bisect view --stat</tt></pre>
415 </div></div>
416 <h3 id="_bisect_log_and_bisect_replay">Bisect log and bisect replay</h3><div style="clear:left"></div>
417 <div class="para"><p>After having marked revisions as good or bad, issue the following
418 command to show what has been done so far:</p></div>
419 <div class="listingblock">
420 <div class="content">
421 <pre><tt>$ git bisect log</tt></pre>
422 </div></div>
423 <div class="para"><p>If you discover that you made a mistake in specifying the status of a
424 revision, you can save the output of this command to a file, edit it to
425 remove the incorrect entries, and then issue the following commands to
426 return to a corrected state:</p></div>
427 <div class="listingblock">
428 <div class="content">
429 <pre><tt>$ git bisect reset
430 $ git bisect replay that-file</tt></pre>
431 </div></div>
432 <h3 id="_avoiding_testing_a_commit">Avoiding testing a commit</h3><div style="clear:left"></div>
433 <div class="para"><p>If, in the middle of a bisect session, you know that the next suggested
434 revision is not a good one to test (e.g. the change the commit
435 introduces is known not to work in your environment and you know it
436 does not have anything to do with the bug you are chasing), you may
437 want to find a nearby commit and try that instead.</p></div>
438 <div class="para"><p>For example:</p></div>
439 <div class="listingblock">
440 <div class="content">
441 <pre><tt>$ git bisect good/bad # previous round was good or bad.
442 Bisecting: 337 revisions left to test after this
443 $ git bisect visualize # oops, that is uninteresting.
444 $ git reset --hard HEAD~3 # try 3 revisions before what
445 # was suggested</tt></pre>
446 </div></div>
447 <div class="para"><p>Then compile and test the chosen revision, and afterwards mark
448 the revision as good or bad in the usual manner.</p></div>
449 <h3 id="_bisect_skip">Bisect skip</h3><div style="clear:left"></div>
450 <div class="para"><p>Instead of choosing by yourself a nearby commit, you can ask git
451 to do it for you by issuing the command:</p></div>
452 <div class="listingblock">
453 <div class="content">
454 <pre><tt>$ git bisect skip # Current version cannot be tested</tt></pre>
455 </div></div>
456 <div class="para"><p>But git may eventually be unable to tell the first bad commit among
457 a bad commit and one or more skipped commits.</p></div>
458 <div class="para"><p>You can even skip a range of commits, instead of just one commit,
459 using the "<em>&lt;commit1&gt;</em>..<em>&lt;commit2&gt;</em>" notation. For example:</p></div>
460 <div class="listingblock">
461 <div class="content">
462 <pre><tt>$ git bisect skip v2.5..v2.6</tt></pre>
463 </div></div>
464 <div class="para"><p>This tells the bisect process that no commit after <tt>v2.5</tt>, up to and
465 including <tt>v2.6</tt>, should be tested.</p></div>
466 <div class="para"><p>Note that if you also want to skip the first commit of the range you
467 would issue the command:</p></div>
468 <div class="listingblock">
469 <div class="content">
470 <pre><tt>$ git bisect skip v2.5 v2.5..v2.6</tt></pre>
471 </div></div>
472 <div class="para"><p>This tells the bisect process that the commits between <tt>v2.5</tt> included
473 and <tt>v2.6</tt> included should be skipped.</p></div>
474 <h3 id="_cutting_down_bisection_by_giving_more_parameters_to_bisect_start">Cutting down bisection by giving more parameters to bisect start</h3><div style="clear:left"></div>
475 <div class="para"><p>You can further cut down the number of trials, if you know what part of
476 the tree is involved in the problem you are tracking down, by specifying
477 path parameters when issuing the <tt>bisect start</tt> command:</p></div>
478 <div class="listingblock">
479 <div class="content">
480 <pre><tt>$ git bisect start -- arch/i386 include/asm-i386</tt></pre>
481 </div></div>
482 <div class="para"><p>If you know beforehand more than one good commit, you can narrow the
483 bisect space down by specifying all of the good commits immediately after
484 the bad commit when issuing the <tt>bisect start</tt> command:</p></div>
485 <div class="listingblock">
486 <div class="content">
487 <pre><tt>$ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --
488 # v2.6.20-rc6 is bad
489 # v2.6.20-rc4 and v2.6.20-rc1 are good</tt></pre>
490 </div></div>
491 <h3 id="_bisect_run">Bisect run</h3><div style="clear:left"></div>
492 <div class="para"><p>If you have a script that can tell if the current source code is good
493 or bad, you can bisect by issuing the command:</p></div>
494 <div class="listingblock">
495 <div class="content">
496 <pre><tt>$ git bisect run my_script arguments</tt></pre>
497 </div></div>
498 <div class="para"><p>Note that the script (<tt>my_script</tt> in the above example) should
499 exit with code 0 if the current source code is good, and exit with a
500 code between 1 and 127 (inclusive), except 125, if the current
501 source code is bad.</p></div>
502 <div class="para"><p>Any other exit code will abort the bisect process. It should be noted
503 that a program that terminates via "exit(-1)" leaves $? = 255, (see the
504 exit(3) manual page), as the value is chopped with "&amp; 0377".</p></div>
505 <div class="para"><p>The special exit code 125 should be used when the current source code
506 cannot be tested. If the script exits with this code, the current
507 revision will be skipped (see <tt>git bisect skip</tt> above).</p></div>
508 <div class="para"><p>You may often find that during a bisect session you want to have
509 temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a
510 header file, or "revision that does not have this commit needs this
511 patch applied to work around another problem this bisection is not
512 interested in") applied to the revision being tested.</p></div>
513 <div class="para"><p>To cope with such a situation, after the inner <em>git bisect</em> finds the
514 next revision to test, the script can apply the patch
515 before compiling, run the real test, and afterwards decide if the
516 revision (possibly with the needed patch) passed the test and then
517 rewind the tree to the pristine state. Finally the script should exit
518 with the status of the real test to let the "git bisect run" command loop
519 determine the eventual outcome of the bisect session.</p></div>
520 </div>
521 <h2 id="_examples">EXAMPLES</h2>
522 <div class="sectionbody">
523 <div class="ilist"><ul>
524 <li>
526 Automatically bisect a broken build between v1.2 and HEAD:
527 </p>
528 <div class="listingblock">
529 <div class="content">
530 <pre><tt>$ git bisect start HEAD v1.2 -- # HEAD is bad, v1.2 is good
531 $ git bisect run make # "make" builds the app</tt></pre>
532 </div></div>
533 </li>
534 <li>
536 Automatically bisect a test failure between origin and HEAD:
537 </p>
538 <div class="listingblock">
539 <div class="content">
540 <pre><tt>$ git bisect start HEAD origin -- # HEAD is bad, origin is good
541 $ git bisect run make test # "make test" builds and tests</tt></pre>
542 </div></div>
543 </li>
544 <li>
546 Automatically bisect a broken test suite:
547 </p>
548 <div class="listingblock">
549 <div class="content">
550 <pre><tt>$ cat ~/test.sh
551 #!/bin/sh
552 make || exit 125 # this skips broken builds
553 make test # "make test" runs the test suite
554 $ git bisect start v1.3 v1.1 -- # v1.3 is bad, v1.1 is good
555 $ git bisect run ~/test.sh</tt></pre>
556 </div></div>
557 <div class="para"><p>Here we use a "test.sh" custom script. In this script, if "make"
558 fails, we skip the current commit.</p></div>
559 <div class="para"><p>It is safer to use a custom script outside the repository to prevent
560 interactions between the bisect, make and test processes and the
561 script.</p></div>
562 <div class="para"><p>"make test" should "exit 0", if the test suite passes, and
563 "exit 1" otherwise.</p></div>
564 </li>
565 <li>
567 Automatically bisect a broken test case:
568 </p>
569 <div class="listingblock">
570 <div class="content">
571 <pre><tt>$ cat ~/test.sh
572 #!/bin/sh
573 make || exit 125 # this skips broken builds
574 ~/check_test_case.sh # does the test case passes ?
575 $ git bisect start HEAD HEAD~10 -- # culprit is among the last 10
576 $ git bisect run ~/test.sh</tt></pre>
577 </div></div>
578 <div class="para"><p>Here "check_test_case.sh" should "exit 0" if the test case passes,
579 and "exit 1" otherwise.</p></div>
580 <div class="para"><p>It is safer if both "test.sh" and "check_test_case.sh" scripts are
581 outside the repository to prevent interactions between the bisect,
582 make and test processes and the scripts.</p></div>
583 </li>
584 <li>
586 Automatically bisect a broken test suite:
587 </p>
588 <div class="listingblock">
589 <div class="content">
590 <pre><tt>$ git bisect start HEAD HEAD~10 -- # culprit is among the last 10
591 $ git bisect run sh -c "make || exit 125; ~/check_test_case.sh"</tt></pre>
592 </div></div>
593 <div class="para"><p>Does the same as the previous example, but on a single line.</p></div>
594 </li>
595 </ul></div>
596 </div>
597 <h2 id="_author">Author</h2>
598 <div class="sectionbody">
599 <div class="para"><p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p></div>
600 </div>
601 <h2 id="_documentation">Documentation</h2>
602 <div class="sectionbody">
603 <div class="para"><p>Documentation by Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p></div>
604 </div>
605 <h2 id="_see_also">SEE ALSO</h2>
606 <div class="sectionbody">
607 <div class="para"><p><a href="git-bisect-lk2009.html">Fighting regressions with git bisect</a>,
608 <a href="git-blame.html">git-blame(1)</a>.</p></div>
609 </div>
610 <h2 id="_git">GIT</h2>
611 <div class="sectionbody">
612 <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
613 </div>
614 <div id="footer">
615 <div id="footer-text">
616 Last updated 2010-02-13 00:59:34 UTC
617 </div>
618 </div>
619 </body>
620 </html>