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">
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">
10 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
12 border: 1px solid red;
17 margin: 1em 5% 1em 5%;
22 text-decoration: underline
;
42 h1
, h2
, h3
, h4
, h5
, h6
{
44 font-family: sans-serif
;
51 border-bottom: 2px solid silver
;
69 border: 1px solid silver
;
88 font-family: sans-serif
;
94 span#revnumber
, span#revdate
, span#revremark
{
95 font-family: sans-serif
;
99 font-family: sans-serif
;
101 border-top: 2px solid silver
;
107 padding-bottom: 0.5em;
111 padding-bottom: 0.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
{
122 margin-bottom: 1.5em;
124 div
.admonitionblock
{
126 margin-bottom: 2.5em;
129 div
.content
{ /* Block element content. */
133 /* Block element titles. */
134 div
.title
, caption
.title
{
136 font-family: sans-serif
;
140 margin-bottom: 0.5em;
146 td div
.title:first-child
{
149 div
.content div
.title:first-child
{
152 div
.content
+ div
.title
{
156 div
.sidebarblock
> div
.content
{
158 border: 1px solid silver
;
162 div
.listingblock
> div
.content
{
163 border: 1px solid silver
;
172 div
.quoteblock
> div
.attribution
{
181 div
.verseblock
> div
.content
{
184 div
.verseblock
> div
.attribution
{
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div
.verseblock
+ div
.attribution
{
193 div
.admonitionblock
.icon
{
197 text-decoration: underline
;
199 padding-right: 0.5em;
201 div
.admonitionblock td
.content
{
203 border-left: 2px solid silver
;
206 div
.exampleblock
> div
.content
{
207 border-left: 2px solid silver
;
211 div
.imageblock div
.content
{ padding-left: 0; }
212 span
.image img
{ border-style: none
; }
213 a
.image:visited
{ color: white
; }
217 margin-bottom: 0.8em;
230 list-style-position: outside
;
233 list-style-type: decimal
;
236 list-style-type: lower-alpha
;
239 list-style-type: upper-alpha
;
242 list-style-type: lower-roman
;
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
{
252 margin-bottom: 0.1em;
255 div
.tableblock
> table
{
256 border: 3px solid
#527bbd;
259 font-family: sans-serif
;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div
.tableblock
> table
[frame
="void"] {
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
;
287 margin-bottom: 0.8em;
290 padding-bottom: 15px;
292 dt
.hdlist1
.strong
, td
.hdlist1
.strong
{
298 padding-right: 0.8em;
304 div
.hdlist
.compact tr
{
314 div#footer-badges
{ display: none
; }
319 font-family: sans-serif
;
323 margin-bottom: 0.1em;
326 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
342 /* Overrides for manpage documents */
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver
;
347 border-bottom: 2px solid silver
;
357 div#toc
{ display: none
; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div
.sidebar-content
{
364 border: 1px solid silver
;
367 div
.sidebar-title
, div
.image-title
{
369 font-family: sans-serif
;
372 margin-bottom: 0.5em;
375 div
.listingblock div
.content
{
376 border: 1px solid silver
;
381 div
.quoteblock-attribution
{
386 div
.verseblock-content
{
389 div
.verseblock-attribution
{
394 div
.exampleblock-content
{
395 border-left: 2px solid silver
;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc
a:visited
{ color: blue
; }
406 git-bisect(
1) Manual Page
409 <div class=
"sectionbody">
411 Find by binary search the change that introduced a bug
415 <h2 id=
"_synopsis">SYNOPSIS
</h2>
416 <div class=
"sectionbody">
417 <div class=
"paragraph"><p><em>git bisect
</em> <subcommand
> <options
></p></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 [
<bad
> [
<good
>...]] [--] [
<paths
>...]
427 git bisect bad [
<rev
>]
428 git bisect good [
<rev
>...]
429 git bisect skip [(
<rev
>|
<range
>)...]
430 git bisect reset [
<commit
>]
432 git bisect replay
<logfile
>
434 git bisect run
<cmd
>...
</tt></pre>
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>
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>
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>
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>
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>
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
488 <div class=
"listingblock">
489 <div class=
"content">
490 <pre><tt>$ git bisect reset
<commit
></tt></pre>
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>
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>
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>
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>
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>
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>
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><commit1></em>..<em><commit2></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>
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>
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>
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 --
583 # v2.6
.20-rc4 and v2.6
.20-rc1 are good
</tt></pre>
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>
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
"& 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).
125 was chosen
602 as the highest sensible value to use for this purpose, because
126 and
127
603 are used by POSIX shells to signal specific error status (
127 is for
604 command not found,
126 is for command found but not executable---these
605 details do not matter, as they are normal errors in the script, as far as
606 "bisect run" is concerned).
</p></div>
607 <div class=
"paragraph"><p>You may often find that during a bisect session you want to have
608 temporary modifications (e.g. s/#define DEBUG
0/#define DEBUG
1/ in a
609 header file, or
"revision that does not have this commit needs this
610 patch applied to work around another problem this bisection is not
611 interested in") applied to the revision being tested.
</p></div>
612 <div class=
"paragraph"><p>To cope with such a situation, after the inner
<em>git bisect
</em> finds the
613 next revision to test, the script can apply the patch
614 before compiling, run the real test, and afterwards decide if the
615 revision (possibly with the needed patch) passed the test and then
616 rewind the tree to the pristine state. Finally the script should exit
617 with the status of the real test to let the
"git bisect run" command loop
618 determine the eventual outcome of the bisect session.
</p></div>
620 <h2 id=
"_examples">EXAMPLES
</h2>
621 <div class=
"sectionbody">
622 <div class=
"ulist"><ul>
625 Automatically bisect a broken build between v1.2 and HEAD:
627 <div class=
"listingblock">
628 <div class=
"content">
629 <pre><tt>$ git bisect start HEAD v1.2 -- # HEAD is bad, v1.2 is good
630 $ git bisect run make #
"make" builds the app
</tt></pre>
635 Automatically bisect a test failure between origin and HEAD:
637 <div class=
"listingblock">
638 <div class=
"content">
639 <pre><tt>$ git bisect start HEAD origin -- # HEAD is bad, origin is good
640 $ git bisect run make test #
"make test" builds and tests
</tt></pre>
645 Automatically bisect a broken test case:
647 <div class=
"listingblock">
648 <div class=
"content">
649 <pre><tt>$ cat ~/test.sh
651 make || exit
125 # this skips broken builds
652 ~/check_test_case.sh # does the test case pass?
653 $ git bisect start HEAD HEAD~
10 -- # culprit is among the last
10
654 $ git bisect run ~/test.sh
</tt></pre>
656 <div class=
"paragraph"><p>Here we use a
"test.sh" custom script. In this script, if
"make"
657 fails, we skip the current commit.
658 "check_test_case.sh" should
"exit 0" if the test case passes,
659 and
"exit 1" otherwise.
</p></div>
660 <div class=
"paragraph"><p>It is safer if both
"test.sh" and
"check_test_case.sh" are
661 outside the repository to prevent interactions between the bisect,
662 make and test processes and the scripts.
</p></div>
666 Automatically bisect with temporary modifications (hot-fix):
668 <div class=
"listingblock">
669 <div class=
"content">
670 <pre><tt>$ cat ~/test.sh
673 # tweak the working tree by merging the hot-fix branch
674 # and then attempt a build
675 if git merge --no-commit hot-fix
&&
678 # run project specific test and report its status
682 # tell the caller this is untestable
686 # undo the tweak to allow clean flipping to the next commit
690 exit $status
</tt></pre>
692 <div class=
"paragraph"><p>This applies modifications from a hot-fix branch before each test run,
693 e.g. in case your build or test environment changed so that older
694 revisions may need a fix which newer ones have already. (Make sure the
695 hot-fix branch is based off a commit which is contained in all revisions
696 which you are bisecting, so that the merge does not pull in too much, or
697 use
<tt>git cherry-pick
</tt> instead of
<tt>git merge
</tt>.)
</p></div>
701 Automatically bisect a broken test case:
703 <div class=
"listingblock">
704 <div class=
"content">
705 <pre><tt>$ git bisect start HEAD HEAD~
10 -- # culprit is among the last
10
706 $ git bisect run sh -c
"make || exit 125; ~/check_test_case.sh"</tt></pre>
708 <div class=
"paragraph"><p>This shows that you can do without a run script if you write the test
709 on a single line.
</p></div>
713 <h2 id=
"_see_also">SEE ALSO
</h2>
714 <div class=
"sectionbody">
715 <div class=
"paragraph"><p><a href=
"git-bisect-lk2009.html">Fighting regressions with git bisect
</a>,
716 <a href=
"git-blame.html">git-blame(
1)
</a>.
</p></div>
718 <h2 id=
"_git">GIT
</h2>
719 <div class=
"sectionbody">
720 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
723 <div id=
"footer-text">
724 Last updated
2011-
03-
23 05:
39:
52 UTC