Documentation / git-bisect.txton commit Merge branch 'jc/sha1-lookup' (e9f9d4f)
   1git-bisect(1)
   2=============
   3
   4NAME
   5----
   6git-bisect - Find the change that introduced a bug by binary search
   7
   8
   9SYNOPSIS
  10--------
  11'git bisect' <subcommand> <options>
  12
  13DESCRIPTION
  14-----------
  15The command takes various subcommands, and different options depending
  16on the subcommand:
  17
  18 git bisect help
  19 git bisect start [<bad> [<good>...]] [--] [<paths>...]
  20 git bisect bad [<rev>]
  21 git bisect good [<rev>...]
  22 git bisect skip [<rev>...]
  23 git bisect reset [<branch>]
  24 git bisect visualize
  25 git bisect replay <logfile>
  26 git bisect log
  27 git bisect run <cmd>...
  28
  29This command uses 'git-rev-list --bisect' option to help drive the
  30binary search process to find which change introduced a bug, given an
  31old "good" commit object name and a later "bad" commit object name.
  32
  33Getting help
  34~~~~~~~~~~~~
  35
  36Use "git bisect" to get a short usage description, and "git bisect
  37help" or "git bisect -h" to get a long usage description.
  38
  39Basic bisect commands: start, bad, good
  40~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41
  42The way you use it is:
  43
  44------------------------------------------------
  45$ git bisect start
  46$ git bisect bad                 # Current version is bad
  47$ git bisect good v2.6.13-rc2    # v2.6.13-rc2 was the last version
  48                                 # tested that was good
  49------------------------------------------------
  50
  51When you give at least one bad and one good versions, it will bisect
  52the revision tree and say something like:
  53
  54------------------------------------------------
  55Bisecting: 675 revisions left to test after this
  56------------------------------------------------
  57
  58and check out the state in the middle. Now, compile that kernel, and
  59boot it. Now, let's say that this booted kernel works fine, then just
  60do
  61
  62------------------------------------------------
  63$ git bisect good                       # this one is good
  64------------------------------------------------
  65
  66which will now say
  67
  68------------------------------------------------
  69Bisecting: 337 revisions left to test after this
  70------------------------------------------------
  71
  72and you continue along, compiling that one, testing it, and depending
  73on whether it is good or bad, you say "git bisect good" or "git bisect
  74bad", and ask for the next bisection.
  75
  76Until you have no more left, and you'll have been left with the first
  77bad kernel rev in "refs/bisect/bad".
  78
  79Bisect reset
  80~~~~~~~~~~~~
  81
  82Oh, and then after you want to reset to the original head, do a
  83
  84------------------------------------------------
  85$ git bisect reset
  86------------------------------------------------
  87
  88to get back to the master branch, instead of being in one of the
  89bisection branches ("git bisect start" will do that for you too,
  90actually: it will reset the bisection state, and before it does that
  91it checks that you're not using some old bisection branch).
  92
  93Bisect visualize
  94~~~~~~~~~~~~~~~~
  95
  96During the bisection process, you can say
  97
  98------------
  99$ git bisect visualize
 100------------
 101
 102to see the currently remaining suspects in `gitk`.  `visualize` is a bit
 103too long to type and `view` is provided as a synonym.
 104
 105If `DISPLAY` environment variable is not set, `git log` is used
 106instead.  You can even give command line options such as `-p` and
 107`--stat`.
 108
 109------------
 110$ git bisect view --stat
 111------------
 112
 113Bisect log and bisect replay
 114~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 115
 116The good/bad input is logged, and
 117
 118------------
 119$ git bisect log
 120------------
 121
 122shows what you have done so far. You can truncate its output somewhere
 123and save it in a file, and run
 124
 125------------
 126$ git bisect replay that-file
 127------------
 128
 129if you find later you made a mistake telling good/bad about a
 130revision.
 131
 132Avoiding to test a commit
 133~~~~~~~~~~~~~~~~~~~~~~~~~
 134
 135If in a middle of bisect session, you know what the bisect suggested
 136to try next is not a good one to test (e.g. the change the commit
 137introduces is known not to work in your environment and you know it
 138does not have anything to do with the bug you are chasing), you may
 139want to find a near-by commit and try that instead.
 140
 141It goes something like this:
 142
 143------------
 144$ git bisect good/bad                   # previous round was good/bad.
 145Bisecting: 337 revisions left to test after this
 146$ git bisect visualize                  # oops, that is uninteresting.
 147$ git reset --hard HEAD~3               # try 3 revs before what
 148                                        # was suggested
 149------------
 150
 151Then compile and test the one you chose to try. After that, tell
 152bisect what the result was as usual.
 153
 154Bisect skip
 155~~~~~~~~~~~~
 156
 157Instead of choosing by yourself a nearby commit, you may just want git
 158to do it for you using:
 159
 160------------
 161$ git bisect skip                 # Current version cannot be tested
 162------------
 163
 164But computing the commit to test may be slower afterwards and git may
 165eventually not be able to tell the first bad among a bad and one or
 166more "skip"ped commits.
 167
 168Cutting down bisection by giving more parameters to bisect start
 169~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 170
 171You can further cut down the number of trials if you know what part of
 172the tree is involved in the problem you are tracking down, by giving
 173paths parameters when you say `bisect start`, like this:
 174
 175------------
 176$ git bisect start -- arch/i386 include/asm-i386
 177------------
 178
 179If you know beforehand more than one good commits, you can narrow the
 180bisect space down without doing the whole tree checkout every time you
 181give good commits. You give the bad revision immediately after `start`
 182and then you give all the good revisions you have:
 183
 184------------
 185$ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --
 186                   # v2.6.20-rc6 is bad
 187                   # v2.6.20-rc4 and v2.6.20-rc1 are good
 188------------
 189
 190Bisect run
 191~~~~~~~~~~
 192
 193If you have a script that can tell if the current source code is good
 194or bad, you can automatically bisect using:
 195
 196------------
 197$ git bisect run my_script
 198------------
 199
 200Note that the "run" script (`my_script` in the above example) should
 201exit with code 0 in case the current source code is good.  Exit with a
 202code between 1 and 127 (inclusive), except 125, if the current
 203source code is bad.
 204
 205Any other exit code will abort the automatic bisect process. (A
 206program that does "exit(-1)" leaves $? = 255, see exit(3) manual page,
 207the value is chopped with "& 0377".)
 208
 209The special exit code 125 should be used when the current source code
 210cannot be tested. If the "run" script exits with this code, the current
 211revision will be skipped, see `git bisect skip` above.
 212
 213You may often find that during bisect you want to have near-constant
 214tweaks (e.g., s/#define DEBUG 0/#define DEBUG 1/ in a header file, or
 215"revision that does not have this commit needs this patch applied to
 216work around other problem this bisection is not interested in")
 217applied to the revision being tested.
 218
 219To cope with such a situation, after the inner git-bisect finds the
 220next revision to test, with the "run" script, you can apply that tweak
 221before compiling, run the real test, and after the test decides if the
 222revision (possibly with the needed tweaks) passed the test, rewind the
 223tree to the pristine state.  Finally the "run" script can exit with
 224the status of the real test to let "git bisect run" command loop to
 225know the outcome.
 226
 227Author
 228------
 229Written by Linus Torvalds <torvalds@osdl.org>
 230
 231Documentation
 232-------------
 233Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
 234
 235GIT
 236---
 237Part of the linkgit:git[7] suite