Autogenerated HTML docs for v1.7.4.1-266-ga62ea
[git/jnareb-git.git] / git-bisect.html
blobf7c2bd0d3bdc50f4f1e9604d18da54dc0a860711
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.4.5" />
7 <title>git-bisect(1)</title>
8 <style type="text/css">
9 /* Debug borders */
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
12 border: 1px solid red;
16 body {
17 margin: 1em 5% 1em 5%;
20 a {
21 color: blue;
22 text-decoration: underline;
24 a:visited {
25 color: fuchsia;
28 em {
29 font-style: italic;
30 color: navy;
33 strong {
34 font-weight: bold;
35 color: #083194;
38 tt {
39 color: navy;
42 h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
50 h1, h2, h3 {
51 border-bottom: 2px solid silver;
53 h2 {
54 padding-top: 0.5em;
56 h3 {
57 float: left;
59 h3 + * {
60 clear: left;
63 div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
68 hr {
69 border: 1px solid silver;
72 p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
77 ul, ol, li > p {
78 margin-top: 0;
81 pre {
82 padding: 0;
83 margin: 0;
86 span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
90 font-size: 1.1em;
92 span#email {
94 span#revnumber, span#revdate, span#revremark {
95 font-family: sans-serif;
98 div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
105 div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
109 div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
114 div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
118 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120 div.admonitionblock {
121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
124 div.admonitionblock {
125 margin-top: 2.5em;
126 margin-bottom: 2.5em;
129 div.content { /* Block element content. */
130 padding: 0;
133 /* Block element titles. */
134 div.title, caption.title {
135 color: #527bbd;
136 font-family: sans-serif;
137 font-weight: bold;
138 text-align: left;
139 margin-top: 1.0em;
140 margin-bottom: 0.5em;
142 div.title + * {
143 margin-top: 0;
146 td div.title:first-child {
147 margin-top: 0.0em;
149 div.content div.title:first-child {
150 margin-top: 0.0em;
152 div.content + div.title {
153 margin-top: 0.0em;
156 div.sidebarblock > div.content {
157 background: #ffffee;
158 border: 1px solid silver;
159 padding: 0.5em;
162 div.listingblock > div.content {
163 border: 1px solid silver;
164 background: #f4f4f4;
165 padding: 0.5em;
168 div.quoteblock {
169 padding-left: 2.0em;
170 margin-right: 10%;
172 div.quoteblock > div.attribution {
173 padding-top: 0.5em;
174 text-align: right;
177 div.verseblock {
178 padding-left: 2.0em;
179 margin-right: 10%;
181 div.verseblock > div.content {
182 white-space: pre;
184 div.verseblock > div.attribution {
185 padding-top: 0.75em;
186 text-align: left;
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div.verseblock + div.attribution {
190 text-align: left;
193 div.admonitionblock .icon {
194 vertical-align: top;
195 font-size: 1.1em;
196 font-weight: bold;
197 text-decoration: underline;
198 color: #527bbd;
199 padding-right: 0.5em;
201 div.admonitionblock td.content {
202 padding-left: 0.5em;
203 border-left: 2px solid silver;
206 div.exampleblock > div.content {
207 border-left: 2px solid silver;
208 padding: 0.5em;
211 div.imageblock div.content { padding-left: 0; }
212 span.image img { border-style: none; }
213 a.image:visited { color: white; }
215 dl {
216 margin-top: 0.8em;
217 margin-bottom: 0.8em;
219 dt {
220 margin-top: 0.5em;
221 margin-bottom: 0;
222 font-style: normal;
223 color: navy;
225 dd > *:first-child {
226 margin-top: 0.1em;
229 ul, ol {
230 list-style-position: outside;
232 ol.arabic {
233 list-style-type: decimal;
235 ol.loweralpha {
236 list-style-type: lower-alpha;
238 ol.upperalpha {
239 list-style-type: upper-alpha;
241 ol.lowerroman {
242 list-style-type: lower-roman;
244 ol.upperroman {
245 list-style-type: upper-roman;
248 div.compact ul, div.compact ol,
249 div.compact p, div.compact p,
250 div.compact div, div.compact div {
251 margin-top: 0.1em;
252 margin-bottom: 0.1em;
255 div.tableblock > table {
256 border: 3px solid #527bbd;
258 thead {
259 font-family: sans-serif;
260 font-weight: bold;
262 tfoot {
263 font-weight: bold;
265 td > div.verse {
266 white-space: pre;
268 p.table {
269 margin-top: 0;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div.tableblock > table[frame="void"] {
273 border-style: none;
275 div.tableblock > table[frame="hsides"] {
276 border-left-style: none;
277 border-right-style: none;
279 div.tableblock > table[frame="vsides"] {
280 border-top-style: none;
281 border-bottom-style: none;
285 div.hdlist {
286 margin-top: 0.8em;
287 margin-bottom: 0.8em;
289 div.hdlist tr {
290 padding-bottom: 15px;
292 dt.hdlist1.strong, td.hdlist1.strong {
293 font-weight: bold;
295 td.hdlist1 {
296 vertical-align: top;
297 font-style: normal;
298 padding-right: 0.8em;
299 color: navy;
301 td.hdlist2 {
302 vertical-align: top;
304 div.hdlist.compact tr {
305 margin: 0;
306 padding-bottom: 0;
309 .comment {
310 background: yellow;
313 @media print {
314 div#footer-badges { display: none; }
317 div#toctitle {
318 color: #527bbd;
319 font-family: sans-serif;
320 font-size: 1.1em;
321 font-weight: bold;
322 margin-top: 1.0em;
323 margin-bottom: 0.1em;
326 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
327 margin-top: 0;
328 margin-bottom: 0;
330 div.toclevel2 {
331 margin-left: 2em;
332 font-size: 0.9em;
334 div.toclevel3 {
335 margin-left: 4em;
336 font-size: 0.9em;
338 div.toclevel4 {
339 margin-left: 6em;
340 font-size: 0.9em;
342 /* Overrides for manpage documents */
343 h1 {
344 padding-top: 0.5em;
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver;
347 border-bottom: 2px solid silver;
349 h2 {
350 border-style: none;
352 div.sectionbody {
353 margin-left: 5%;
356 @media print {
357 div#toc { display: none; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div.sidebar-content {
363 background: #ffffee;
364 border: 1px solid silver;
365 padding: 0.5em;
367 div.sidebar-title, div.image-title {
368 color: #527bbd;
369 font-family: sans-serif;
370 font-weight: bold;
371 margin-top: 0.0em;
372 margin-bottom: 0.5em;
375 div.listingblock div.content {
376 border: 1px solid silver;
377 background: #f4f4f4;
378 padding: 0.5em;
381 div.quoteblock-attribution {
382 padding-top: 0.5em;
383 text-align: right;
386 div.verseblock-content {
387 white-space: pre;
389 div.verseblock-attribution {
390 padding-top: 0.75em;
391 text-align: left;
394 div.exampleblock-content {
395 border-left: 2px solid silver;
396 padding-left: 0.5em;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc a:visited { color: blue; }
401 </style>
402 </head>
403 <body>
404 <div id="header">
405 <h1>
406 git-bisect(1) Manual Page
407 </h1>
408 <h2>NAME</h2>
409 <div class="sectionbody">
410 <p>git-bisect -
411 Find by binary search the change that introduced a bug
412 </p>
413 </div>
414 </div>
415 <h2 id="_synopsis">SYNOPSIS</h2>
416 <div class="sectionbody">
417 <div class="paragraph"><p><em>git bisect</em> &lt;subcommand&gt; &lt;options&gt;</p></div>
418 </div>
419 <h2 id="_description">DESCRIPTION</h2>
420 <div class="sectionbody">
421 <div class="paragraph"><p>The command takes various subcommands, and different options depending
422 on the subcommand:</p></div>
423 <div class="literalblock">
424 <div class="content">
425 <pre><tt>git bisect help
426 git bisect start [&lt;bad&gt; [&lt;good&gt;...]] [--] [&lt;paths&gt;...]
427 git bisect bad [&lt;rev&gt;]
428 git bisect good [&lt;rev&gt;...]
429 git bisect skip [(&lt;rev&gt;|&lt;range&gt;)...]
430 git bisect reset [&lt;commit&gt;]
431 git bisect visualize
432 git bisect replay &lt;logfile&gt;
433 git bisect log
434 git bisect run &lt;cmd&gt;...</tt></pre>
435 </div></div>
436 <div class="paragraph"><p>This command uses <em>git rev-list --bisect</em> to help drive the
437 binary search process to find which change introduced a bug, given an
438 old "good" commit object name and a later "bad" commit object name.</p></div>
439 <h3 id="_getting_help">Getting help</h3><div style="clear:left"></div>
440 <div class="paragraph"><p>Use "git bisect" to get a short usage description, and "git bisect
441 help" or "git bisect -h" to get a long usage description.</p></div>
442 <h3 id="_basic_bisect_commands_start_bad_good">Basic bisect commands: start, bad, good</h3><div style="clear:left"></div>
443 <div class="paragraph"><p>Using the Linux kernel tree as an example, basic use of the bisect
444 command is as follows:</p></div>
445 <div class="listingblock">
446 <div class="content">
447 <pre><tt>$ git bisect start
448 $ git bisect bad # Current version is bad
449 $ git bisect good v2.6.13-rc2 # v2.6.13-rc2 was the last version
450 # tested that was good</tt></pre>
451 </div></div>
452 <div class="paragraph"><p>When you have specified at least one bad and one good version, the
453 command bisects the revision tree and outputs something similar to
454 the following:</p></div>
455 <div class="listingblock">
456 <div class="content">
457 <pre><tt>Bisecting: 675 revisions left to test after this</tt></pre>
458 </div></div>
459 <div class="paragraph"><p>The state in the middle of the set of revisions is then checked out.
460 You would now compile that kernel and boot it. If the booted kernel
461 works correctly, you would then issue the following command:</p></div>
462 <div class="listingblock">
463 <div class="content">
464 <pre><tt>$ git bisect good # this one is good</tt></pre>
465 </div></div>
466 <div class="paragraph"><p>The output of this command would be something similar to the following:</p></div>
467 <div class="listingblock">
468 <div class="content">
469 <pre><tt>Bisecting: 337 revisions left to test after this</tt></pre>
470 </div></div>
471 <div class="paragraph"><p>You keep repeating this process, compiling the tree, testing it, and
472 depending on whether it is good or bad issuing the command "git bisect good"
473 or "git bisect bad" to ask for the next bisection.</p></div>
474 <div class="paragraph"><p>Eventually there will be no more revisions left to bisect, and you
475 will have been left with the first bad kernel revision in "refs/bisect/bad".</p></div>
476 <h3 id="_bisect_reset">Bisect reset</h3><div style="clear:left"></div>
477 <div class="paragraph"><p>After a bisect session, to clean up the bisection state and return to
478 the original HEAD, issue the following command:</p></div>
479 <div class="listingblock">
480 <div class="content">
481 <pre><tt>$ git bisect reset</tt></pre>
482 </div></div>
483 <div class="paragraph"><p>By default, this will return your tree to the commit that was checked
484 out before <tt>git bisect start</tt>. (A new <tt>git bisect start</tt> will also do
485 that, as it cleans up the old bisection state.)</p></div>
486 <div class="paragraph"><p>With an optional argument, you can return to a different commit
487 instead:</p></div>
488 <div class="listingblock">
489 <div class="content">
490 <pre><tt>$ git bisect reset &lt;commit&gt;</tt></pre>
491 </div></div>
492 <div class="paragraph"><p>For example, <tt>git bisect reset HEAD</tt> will leave you on the current
493 bisection commit and avoid switching commits at all, while <tt>git bisect
494 reset bisect/bad</tt> will check out the first bad revision.</p></div>
495 <h3 id="_bisect_visualize">Bisect visualize</h3><div style="clear:left"></div>
496 <div class="paragraph"><p>To see the currently remaining suspects in <em>gitk</em>, issue the following
497 command during the bisection process:</p></div>
498 <div class="listingblock">
499 <div class="content">
500 <pre><tt>$ git bisect visualize</tt></pre>
501 </div></div>
502 <div class="paragraph"><p><tt>view</tt> may also be used as a synonym for <tt>visualize</tt>.</p></div>
503 <div class="paragraph"><p>If the <em>DISPLAY</em> environment variable is not set, <em>git log</em> is used
504 instead. You can also give command line options such as <tt>-p</tt> and
505 <tt>--stat</tt>.</p></div>
506 <div class="listingblock">
507 <div class="content">
508 <pre><tt>$ git bisect view --stat</tt></pre>
509 </div></div>
510 <h3 id="_bisect_log_and_bisect_replay">Bisect log and bisect replay</h3><div style="clear:left"></div>
511 <div class="paragraph"><p>After having marked revisions as good or bad, issue the following
512 command to show what has been done so far:</p></div>
513 <div class="listingblock">
514 <div class="content">
515 <pre><tt>$ git bisect log</tt></pre>
516 </div></div>
517 <div class="paragraph"><p>If you discover that you made a mistake in specifying the status of a
518 revision, you can save the output of this command to a file, edit it to
519 remove the incorrect entries, and then issue the following commands to
520 return to a corrected state:</p></div>
521 <div class="listingblock">
522 <div class="content">
523 <pre><tt>$ git bisect reset
524 $ git bisect replay that-file</tt></pre>
525 </div></div>
526 <h3 id="_avoiding_testing_a_commit">Avoiding testing a commit</h3><div style="clear:left"></div>
527 <div class="paragraph"><p>If, in the middle of a bisect session, you know that the next suggested
528 revision is not a good one to test (e.g. the change the commit
529 introduces is known not to work in your environment and you know it
530 does not have anything to do with the bug you are chasing), you may
531 want to find a nearby commit and try that instead.</p></div>
532 <div class="paragraph"><p>For example:</p></div>
533 <div class="listingblock">
534 <div class="content">
535 <pre><tt>$ git bisect good/bad # previous round was good or bad.
536 Bisecting: 337 revisions left to test after this
537 $ git bisect visualize # oops, that is uninteresting.
538 $ git reset --hard HEAD~3 # try 3 revisions before what
539 # was suggested</tt></pre>
540 </div></div>
541 <div class="paragraph"><p>Then compile and test the chosen revision, and afterwards mark
542 the revision as good or bad in the usual manner.</p></div>
543 <h3 id="_bisect_skip">Bisect skip</h3><div style="clear:left"></div>
544 <div class="paragraph"><p>Instead of choosing by yourself a nearby commit, you can ask git
545 to do it for you by issuing the command:</p></div>
546 <div class="listingblock">
547 <div class="content">
548 <pre><tt>$ git bisect skip # Current version cannot be tested</tt></pre>
549 </div></div>
550 <div class="paragraph"><p>But git may eventually be unable to tell the first bad commit among
551 a bad commit and one or more skipped commits.</p></div>
552 <div class="paragraph"><p>You can even skip a range of commits, instead of just one commit,
553 using the "<em>&lt;commit1&gt;</em>..<em>&lt;commit2&gt;</em>" notation. For example:</p></div>
554 <div class="listingblock">
555 <div class="content">
556 <pre><tt>$ git bisect skip v2.5..v2.6</tt></pre>
557 </div></div>
558 <div class="paragraph"><p>This tells the bisect process that no commit after <tt>v2.5</tt>, up to and
559 including <tt>v2.6</tt>, should be tested.</p></div>
560 <div class="paragraph"><p>Note that if you also want to skip the first commit of the range you
561 would issue the command:</p></div>
562 <div class="listingblock">
563 <div class="content">
564 <pre><tt>$ git bisect skip v2.5 v2.5..v2.6</tt></pre>
565 </div></div>
566 <div class="paragraph"><p>This tells the bisect process that the commits between <tt>v2.5</tt> included
567 and <tt>v2.6</tt> included should be skipped.</p></div>
568 <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>
569 <div class="paragraph"><p>You can further cut down the number of trials, if you know what part of
570 the tree is involved in the problem you are tracking down, by specifying
571 path parameters when issuing the <tt>bisect start</tt> command:</p></div>
572 <div class="listingblock">
573 <div class="content">
574 <pre><tt>$ git bisect start -- arch/i386 include/asm-i386</tt></pre>
575 </div></div>
576 <div class="paragraph"><p>If you know beforehand more than one good commit, you can narrow the
577 bisect space down by specifying all of the good commits immediately after
578 the bad commit when issuing the <tt>bisect start</tt> command:</p></div>
579 <div class="listingblock">
580 <div class="content">
581 <pre><tt>$ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --
582 # v2.6.20-rc6 is bad
583 # v2.6.20-rc4 and v2.6.20-rc1 are good</tt></pre>
584 </div></div>
585 <h3 id="_bisect_run">Bisect run</h3><div style="clear:left"></div>
586 <div class="paragraph"><p>If you have a script that can tell if the current source code is good
587 or bad, you can bisect by issuing the command:</p></div>
588 <div class="listingblock">
589 <div class="content">
590 <pre><tt>$ git bisect run my_script arguments</tt></pre>
591 </div></div>
592 <div class="paragraph"><p>Note that the script (<tt>my_script</tt> in the above example) should
593 exit with code 0 if the current source code is good, and exit with a
594 code between 1 and 127 (inclusive), except 125, if the current
595 source code is bad.</p></div>
596 <div class="paragraph"><p>Any other exit code will abort the bisect process. It should be noted
597 that a program that terminates via "exit(-1)" leaves $? = 255, (see the
598 exit(3) manual page), as the value is chopped with "&amp; 0377".</p></div>
599 <div class="paragraph"><p>The special exit code 125 should be used when the current source code
600 cannot be tested. If the script exits with this code, the current
601 revision will be skipped (see <tt>git bisect skip</tt> above).</p></div>
602 <div class="paragraph"><p>You may often find that during a bisect session you want to have
603 temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a
604 header file, or "revision that does not have this commit needs this
605 patch applied to work around another problem this bisection is not
606 interested in") applied to the revision being tested.</p></div>
607 <div class="paragraph"><p>To cope with such a situation, after the inner <em>git bisect</em> finds the
608 next revision to test, the script can apply the patch
609 before compiling, run the real test, and afterwards decide if the
610 revision (possibly with the needed patch) passed the test and then
611 rewind the tree to the pristine state. Finally the script should exit
612 with the status of the real test to let the "git bisect run" command loop
613 determine the eventual outcome of the bisect session.</p></div>
614 </div>
615 <h2 id="_examples">EXAMPLES</h2>
616 <div class="sectionbody">
617 <div class="ulist"><ul>
618 <li>
620 Automatically bisect a broken build between v1.2 and HEAD:
621 </p>
622 <div class="listingblock">
623 <div class="content">
624 <pre><tt>$ git bisect start HEAD v1.2 -- # HEAD is bad, v1.2 is good
625 $ git bisect run make # "make" builds the app</tt></pre>
626 </div></div>
627 </li>
628 <li>
630 Automatically bisect a test failure between origin and HEAD:
631 </p>
632 <div class="listingblock">
633 <div class="content">
634 <pre><tt>$ git bisect start HEAD origin -- # HEAD is bad, origin is good
635 $ git bisect run make test # "make test" builds and tests</tt></pre>
636 </div></div>
637 </li>
638 <li>
640 Automatically bisect a broken test suite:
641 </p>
642 <div class="listingblock">
643 <div class="content">
644 <pre><tt>$ cat ~/test.sh
645 #!/bin/sh
646 make || exit 125 # this skips broken builds
647 make test # "make test" runs the test suite
648 $ git bisect start v1.3 v1.1 -- # v1.3 is bad, v1.1 is good
649 $ git bisect run ~/test.sh</tt></pre>
650 </div></div>
651 <div class="paragraph"><p>Here we use a "test.sh" custom script. In this script, if "make"
652 fails, we skip the current commit.</p></div>
653 <div class="paragraph"><p>It is safer to use a custom script outside the repository to prevent
654 interactions between the bisect, make and test processes and the
655 script.</p></div>
656 <div class="paragraph"><p>"make test" should "exit 0", if the test suite passes, and
657 "exit 1" otherwise.</p></div>
658 </li>
659 <li>
661 Automatically bisect a broken test case:
662 </p>
663 <div class="listingblock">
664 <div class="content">
665 <pre><tt>$ cat ~/test.sh
666 #!/bin/sh
667 make || exit 125 # this skips broken builds
668 ~/check_test_case.sh # does the test case passes ?
669 $ git bisect start HEAD HEAD~10 -- # culprit is among the last 10
670 $ git bisect run ~/test.sh</tt></pre>
671 </div></div>
672 <div class="paragraph"><p>Here "check_test_case.sh" should "exit 0" if the test case passes,
673 and "exit 1" otherwise.</p></div>
674 <div class="paragraph"><p>It is safer if both "test.sh" and "check_test_case.sh" scripts are
675 outside the repository to prevent interactions between the bisect,
676 make and test processes and the scripts.</p></div>
677 </li>
678 <li>
680 Automatically bisect a broken test suite:
681 </p>
682 <div class="listingblock">
683 <div class="content">
684 <pre><tt>$ git bisect start HEAD HEAD~10 -- # culprit is among the last 10
685 $ git bisect run sh -c "make || exit 125; ~/check_test_case.sh"</tt></pre>
686 </div></div>
687 <div class="paragraph"><p>Does the same as the previous example, but on a single line.</p></div>
688 </li>
689 </ul></div>
690 </div>
691 <h2 id="_see_also">SEE ALSO</h2>
692 <div class="sectionbody">
693 <div class="paragraph"><p><a href="git-bisect-lk2009.html">Fighting regressions with git bisect</a>,
694 <a href="git-blame.html">git-blame(1)</a>.</p></div>
695 </div>
696 <h2 id="_git">GIT</h2>
697 <div class="sectionbody">
698 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
699 </div>
700 <div id="footer">
701 <div id="footer-text">
702 Last updated 2011-03-15 23:30:13 UTC
703 </div>
704 </div>
705 </body>
706 </html>