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=
"verseblock">
418 <div class=
"verseblock-content"><em>git bisect
</em> <subcommand
> <options
></div>
419 <div class=
"verseblock-attribution">
422 <h2 id=
"_description">DESCRIPTION
</h2>
423 <div class=
"sectionbody">
424 <div class=
"paragraph"><p>The command takes various subcommands, and different options depending
425 on the subcommand:
</p></div>
426 <div class=
"literalblock">
427 <div class=
"content">
428 <pre><tt>git bisect help
429 git bisect start [--no-checkout] [
<bad
> [
<good
>...]] [--] [
<paths
>...]
430 git bisect bad [
<rev
>]
431 git bisect good [
<rev
>...]
432 git bisect skip [(
<rev
>|
<range
>)...]
433 git bisect reset [
<commit
>]
435 git bisect replay
<logfile
>
437 git bisect run
<cmd
>...
</tt></pre>
439 <div class=
"paragraph"><p>This command uses
<em>git rev-list --bisect
</em> to help drive the
440 binary search process to find which change introduced a bug, given an
441 old
"good" commit object name and a later
"bad" commit object name.
</p></div>
442 <h3 id=
"_getting_help">Getting help
</h3><div style=
"clear:left"></div>
443 <div class=
"paragraph"><p>Use
"git bisect" to get a short usage description, and
"git bisect
444 help" or
"git bisect -h" to get a long usage description.
</p></div>
445 <h3 id=
"_basic_bisect_commands_start_bad_good">Basic bisect commands: start, bad, good
</h3><div style=
"clear:left"></div>
446 <div class=
"paragraph"><p>Using the Linux kernel tree as an example, basic use of the bisect
447 command is as follows:
</p></div>
448 <div class=
"listingblock">
449 <div class=
"content">
450 <pre><tt>$ git bisect start
451 $ git bisect bad # Current version is bad
452 $ git bisect good v2.6
.13-rc2 # v2.6
.13-rc2 was the last version
453 # tested that was good
</tt></pre>
455 <div class=
"paragraph"><p>When you have specified at least one bad and one good version, the
456 command bisects the revision tree and outputs something similar to
457 the following:
</p></div>
458 <div class=
"listingblock">
459 <div class=
"content">
460 <pre><tt>Bisecting:
675 revisions left to test after this
</tt></pre>
462 <div class=
"paragraph"><p>The state in the middle of the set of revisions is then checked out.
463 You would now compile that kernel and boot it. If the booted kernel
464 works correctly, you would then issue the following command:
</p></div>
465 <div class=
"listingblock">
466 <div class=
"content">
467 <pre><tt>$ git bisect good # this one is good
</tt></pre>
469 <div class=
"paragraph"><p>The output of this command would be something similar to the following:
</p></div>
470 <div class=
"listingblock">
471 <div class=
"content">
472 <pre><tt>Bisecting:
337 revisions left to test after this
</tt></pre>
474 <div class=
"paragraph"><p>You keep repeating this process, compiling the tree, testing it, and
475 depending on whether it is good or bad issuing the command
"git bisect good"
476 or
"git bisect bad" to ask for the next bisection.
</p></div>
477 <div class=
"paragraph"><p>Eventually there will be no more revisions left to bisect, and you
478 will have been left with the first bad kernel revision in
"refs/bisect/bad".
</p></div>
479 <h3 id=
"_bisect_reset">Bisect reset
</h3><div style=
"clear:left"></div>
480 <div class=
"paragraph"><p>After a bisect session, to clean up the bisection state and return to
481 the original HEAD, issue the following command:
</p></div>
482 <div class=
"listingblock">
483 <div class=
"content">
484 <pre><tt>$ git bisect reset
</tt></pre>
486 <div class=
"paragraph"><p>By default, this will return your tree to the commit that was checked
487 out before
<tt>git bisect start
</tt>. (A new
<tt>git bisect start
</tt> will also do
488 that, as it cleans up the old bisection state.)
</p></div>
489 <div class=
"paragraph"><p>With an optional argument, you can return to a different commit
491 <div class=
"listingblock">
492 <div class=
"content">
493 <pre><tt>$ git bisect reset
<commit
></tt></pre>
495 <div class=
"paragraph"><p>For example,
<tt>git bisect reset HEAD
</tt> will leave you on the current
496 bisection commit and avoid switching commits at all, while
<tt>git bisect
497 reset bisect/bad
</tt> will check out the first bad revision.
</p></div>
498 <h3 id=
"_bisect_visualize">Bisect visualize
</h3><div style=
"clear:left"></div>
499 <div class=
"paragraph"><p>To see the currently remaining suspects in
<em>gitk
</em>, issue the following
500 command during the bisection process:
</p></div>
501 <div class=
"listingblock">
502 <div class=
"content">
503 <pre><tt>$ git bisect visualize
</tt></pre>
505 <div class=
"paragraph"><p><tt>view
</tt> may also be used as a synonym for
<tt>visualize
</tt>.
</p></div>
506 <div class=
"paragraph"><p>If the
<em>DISPLAY
</em> environment variable is not set,
<em>git log
</em> is used
507 instead. You can also give command line options such as
<tt>-p
</tt> and
508 <tt>--stat
</tt>.
</p></div>
509 <div class=
"listingblock">
510 <div class=
"content">
511 <pre><tt>$ git bisect view --stat
</tt></pre>
513 <h3 id=
"_bisect_log_and_bisect_replay">Bisect log and bisect replay
</h3><div style=
"clear:left"></div>
514 <div class=
"paragraph"><p>After having marked revisions as good or bad, issue the following
515 command to show what has been done so far:
</p></div>
516 <div class=
"listingblock">
517 <div class=
"content">
518 <pre><tt>$ git bisect log
</tt></pre>
520 <div class=
"paragraph"><p>If you discover that you made a mistake in specifying the status of a
521 revision, you can save the output of this command to a file, edit it to
522 remove the incorrect entries, and then issue the following commands to
523 return to a corrected state:
</p></div>
524 <div class=
"listingblock">
525 <div class=
"content">
526 <pre><tt>$ git bisect reset
527 $ git bisect replay that-file
</tt></pre>
529 <h3 id=
"_avoiding_testing_a_commit">Avoiding testing a commit
</h3><div style=
"clear:left"></div>
530 <div class=
"paragraph"><p>If, in the middle of a bisect session, you know that the next suggested
531 revision is not a good one to test (e.g. the change the commit
532 introduces is known not to work in your environment and you know it
533 does not have anything to do with the bug you are chasing), you may
534 want to find a nearby commit and try that instead.
</p></div>
535 <div class=
"paragraph"><p>For example:
</p></div>
536 <div class=
"listingblock">
537 <div class=
"content">
538 <pre><tt>$ git bisect good/bad # previous round was good or bad.
539 Bisecting:
337 revisions left to test after this
540 $ git bisect visualize # oops, that is uninteresting.
541 $ git reset --hard HEAD~
3 # try
3 revisions before what
542 # was suggested
</tt></pre>
544 <div class=
"paragraph"><p>Then compile and test the chosen revision, and afterwards mark
545 the revision as good or bad in the usual manner.
</p></div>
546 <h3 id=
"_bisect_skip">Bisect skip
</h3><div style=
"clear:left"></div>
547 <div class=
"paragraph"><p>Instead of choosing by yourself a nearby commit, you can ask git
548 to do it for you by issuing the command:
</p></div>
549 <div class=
"listingblock">
550 <div class=
"content">
551 <pre><tt>$ git bisect skip # Current version cannot be tested
</tt></pre>
553 <div class=
"paragraph"><p>But git may eventually be unable to tell the first bad commit among
554 a bad commit and one or more skipped commits.
</p></div>
555 <div class=
"paragraph"><p>You can even skip a range of commits, instead of just one commit,
556 using the
"<em><commit1></em>..<em><commit2></em>" notation. For example:
</p></div>
557 <div class=
"listingblock">
558 <div class=
"content">
559 <pre><tt>$ git bisect skip v2.5..v2.6
</tt></pre>
561 <div class=
"paragraph"><p>This tells the bisect process that no commit after
<tt>v2.5
</tt>, up to and
562 including
<tt>v2.6
</tt>, should be tested.
</p></div>
563 <div class=
"paragraph"><p>Note that if you also want to skip the first commit of the range you
564 would issue the command:
</p></div>
565 <div class=
"listingblock">
566 <div class=
"content">
567 <pre><tt>$ git bisect skip v2.5 v2.5..v2.6
</tt></pre>
569 <div class=
"paragraph"><p>This tells the bisect process that the commits between
<tt>v2.5
</tt> included
570 and
<tt>v2.6
</tt> included should be skipped.
</p></div>
571 <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>
572 <div class=
"paragraph"><p>You can further cut down the number of trials, if you know what part of
573 the tree is involved in the problem you are tracking down, by specifying
574 path parameters when issuing the
<tt>bisect start
</tt> command:
</p></div>
575 <div class=
"listingblock">
576 <div class=
"content">
577 <pre><tt>$ git bisect start -- arch/i386 include/asm-i386
</tt></pre>
579 <div class=
"paragraph"><p>If you know beforehand more than one good commit, you can narrow the
580 bisect space down by specifying all of the good commits immediately after
581 the bad commit when issuing the
<tt>bisect start
</tt> command:
</p></div>
582 <div class=
"listingblock">
583 <div class=
"content">
584 <pre><tt>$ git bisect start v2.6
.20-rc6 v2.6
.20-rc4 v2.6
.20-rc1 --
586 # v2.6
.20-rc4 and v2.6
.20-rc1 are good
</tt></pre>
588 <h3 id=
"_bisect_run">Bisect run
</h3><div style=
"clear:left"></div>
589 <div class=
"paragraph"><p>If you have a script that can tell if the current source code is good
590 or bad, you can bisect by issuing the command:
</p></div>
591 <div class=
"listingblock">
592 <div class=
"content">
593 <pre><tt>$ git bisect run my_script arguments
</tt></pre>
595 <div class=
"paragraph"><p>Note that the script (
<tt>my_script
</tt> in the above example) should
596 exit with code
0 if the current source code is good, and exit with a
597 code between
1 and
127 (inclusive), except
125, if the current
598 source code is bad.
</p></div>
599 <div class=
"paragraph"><p>Any other exit code will abort the bisect process. It should be noted
600 that a program that terminates via
"exit(-1)" leaves $? =
255, (see the
601 exit(
3) manual page), as the value is chopped with
"& 0377".
</p></div>
602 <div class=
"paragraph"><p>The special exit code
125 should be used when the current source code
603 cannot be tested. If the script exits with this code, the current
604 revision will be skipped (see
<tt>git bisect skip
</tt> above).
125 was chosen
605 as the highest sensible value to use for this purpose, because
126 and
127
606 are used by POSIX shells to signal specific error status (
127 is for
607 command not found,
126 is for command found but not executable---these
608 details do not matter, as they are normal errors in the script, as far as
609 "bisect run" is concerned).
</p></div>
610 <div class=
"paragraph"><p>You may often find that during a bisect session you want to have
611 temporary modifications (e.g. s/#define DEBUG
0/#define DEBUG
1/ in a
612 header file, or
"revision that does not have this commit needs this
613 patch applied to work around another problem this bisection is not
614 interested in") applied to the revision being tested.
</p></div>
615 <div class=
"paragraph"><p>To cope with such a situation, after the inner
<em>git bisect
</em> finds the
616 next revision to test, the script can apply the patch
617 before compiling, run the real test, and afterwards decide if the
618 revision (possibly with the needed patch) passed the test and then
619 rewind the tree to the pristine state. Finally the script should exit
620 with the status of the real test to let the
"git bisect run" command loop
621 determine the eventual outcome of the bisect session.
</p></div>
623 <h2 id=
"_options">OPTIONS
</h2>
624 <div class=
"sectionbody">
625 <div class=
"dlist"><dl>
630 <div class=
"paragraph"><p>Do not checkout the new working tree at each iteration of the bisection
631 process. Instead just update a special reference named
<em>BISECT_HEAD
</em> to make
632 it point to the commit that should be tested.
</p></div>
633 <div class=
"paragraph"><p>This option may be useful when the test you would perform in each step
634 does not require a checked out tree.
</p></div>
635 <div class=
"paragraph"><p>If the repository is bare,
<tt>--no-checkout
</tt> is assumed.
</p></div>
639 <h2 id=
"_examples">EXAMPLES
</h2>
640 <div class=
"sectionbody">
641 <div class=
"ulist"><ul>
644 Automatically bisect a broken build between v1.2 and HEAD:
646 <div class=
"listingblock">
647 <div class=
"content">
648 <pre><tt>$ git bisect start HEAD v1.2 -- # HEAD is bad, v1.2 is good
649 $ git bisect run make #
"make" builds the app
</tt></pre>
654 Automatically bisect a test failure between origin and HEAD:
656 <div class=
"listingblock">
657 <div class=
"content">
658 <pre><tt>$ git bisect start HEAD origin -- # HEAD is bad, origin is good
659 $ git bisect run make test #
"make test" builds and tests
</tt></pre>
664 Automatically bisect a broken test case:
666 <div class=
"listingblock">
667 <div class=
"content">
668 <pre><tt>$ cat ~/test.sh
670 make || exit
125 # this skips broken builds
671 ~/check_test_case.sh # does the test case pass?
672 $ git bisect start HEAD HEAD~
10 -- # culprit is among the last
10
673 $ git bisect run ~/test.sh
</tt></pre>
675 <div class=
"paragraph"><p>Here we use a
"test.sh" custom script. In this script, if
"make"
676 fails, we skip the current commit.
677 "check_test_case.sh" should
"exit 0" if the test case passes,
678 and
"exit 1" otherwise.
</p></div>
679 <div class=
"paragraph"><p>It is safer if both
"test.sh" and
"check_test_case.sh" are
680 outside the repository to prevent interactions between the bisect,
681 make and test processes and the scripts.
</p></div>
685 Automatically bisect with temporary modifications (hot-fix):
687 <div class=
"listingblock">
688 <div class=
"content">
689 <pre><tt>$ cat ~/test.sh
692 # tweak the working tree by merging the hot-fix branch
693 # and then attempt a build
694 if git merge --no-commit hot-fix
&&
697 # run project specific test and report its status
701 # tell the caller this is untestable
705 # undo the tweak to allow clean flipping to the next commit
709 exit $status
</tt></pre>
711 <div class=
"paragraph"><p>This applies modifications from a hot-fix branch before each test run,
712 e.g. in case your build or test environment changed so that older
713 revisions may need a fix which newer ones have already. (Make sure the
714 hot-fix branch is based off a commit which is contained in all revisions
715 which you are bisecting, so that the merge does not pull in too much, or
716 use
<tt>git cherry-pick
</tt> instead of
<tt>git merge
</tt>.)
</p></div>
720 Automatically bisect a broken test case:
722 <div class=
"listingblock">
723 <div class=
"content">
724 <pre><tt>$ git bisect start HEAD HEAD~
10 -- # culprit is among the last
10
725 $ git bisect run sh -c
"make || exit 125; ~/check_test_case.sh"</tt></pre>
727 <div class=
"paragraph"><p>This shows that you can do without a run script if you write the test
728 on a single line.
</p></div>
732 Locate a good region of the object graph in a damaged repository
734 <div class=
"listingblock">
735 <div class=
"content">
736 <pre><tt>$ git bisect start HEAD
<known-good-commit
> [
<boundary-commit
> ... ] --no-checkout
737 $ git bisect run sh -c '
738 GOOD=$(git for-each-ref
"--format=%(objectname)" refs/bisect/good-*)
&&
739 git rev-list --objects BISECT_HEAD --not $GOOD
>tmp.$$
&&
740 git pack-objects --stdout
>/dev/null
<tmp.$$
743 test $rc =
0'
</tt></pre>
745 <div class=
"paragraph"><p>In this case, when
<em>git bisect run
</em> finishes, bisect/bad will refer to a commit that
746 has at least one parent whose reachable graph is fully traversable in the sense
747 required by
<em>git pack objects
</em>.
</p></div>
751 <h2 id=
"_see_also">SEE ALSO
</h2>
752 <div class=
"sectionbody">
753 <div class=
"paragraph"><p><a href=
"git-bisect-lk2009.html">Fighting regressions with git bisect
</a>,
754 <a href=
"git-blame.html">git-blame(
1)
</a>.
</p></div>
756 <h2 id=
"_git">GIT
</h2>
757 <div class=
"sectionbody">
758 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
761 <div id=
"footer-text">
762 Last updated
2011-
08-
18 06:
09:
28 UTC