blob: 4b45d837a7e7c590fe3aa5f575009c43342b833c [file] [log] [blame]
Junio C Hamano215a7ad2005-09-07 17:26:23 -07001git-bisect(1)
2=============
Junio C Hamano7fc9d692005-08-23 01:49:47 -07003
4NAME
5----
Michael Haggerty2df5a842015-06-26 22:22:46 +02006git-bisect - Use binary search to find the commit that introduced a bug
Junio C Hamano7fc9d692005-08-23 01:49:47 -07007
8
9SYNOPSIS
10--------
Martin von Zweigbergk7791a1d2011-07-01 22:38:26 -040011[verse]
Junio C Hamanoa6080a02007-06-07 00:04:01 -070012'git bisect' <subcommand> <options>
Junio C Hamano7fc9d692005-08-23 01:49:47 -070013
14DESCRIPTION
15-----------
Christian Couderfed820a2007-03-24 06:31:49 +010016The command takes various subcommands, and different options depending
17on the subcommand:
Junio C Hamano556cb4e2005-12-05 00:15:24 -080018
Matthieu Moy06e6a742015-06-29 17:40:35 +020019 git bisect start [--term-{old,good}=<term> --term-{new,bad}=<term>]
20 [--no-checkout] [<bad> [<good>...]] [--] [<paths>...]
Christian Couder3f054022017-01-13 15:44:05 +010021 git bisect (bad|new|<term-new>) [<rev>]
22 git bisect (good|old|<term-old>) [<rev>...]
Matthieu Moy21b55e32015-06-29 17:40:34 +020023 git bisect terms [--term-good | --term-bad]
Christian Couder54138122008-12-02 14:53:51 +010024 git bisect skip [(<rev>|<range>)...]
Anders Kaseorg6b87ce22009-10-13 17:02:24 -040025 git bisect reset [<commit>]
Robert P. J. Daydbc349b2017-11-12 04:30:38 -050026 git bisect (visualize|view)
Junio C Hamano556cb4e2005-12-05 00:15:24 -080027 git bisect replay <logfile>
28 git bisect log
Christian Coudera17c4102007-03-23 08:49:59 +010029 git bisect run <cmd>...
Michael Haggerty2df5a842015-06-26 22:22:46 +020030 git bisect help
Junio C Hamano556cb4e2005-12-05 00:15:24 -080031
Michael Haggerty2df5a842015-06-26 22:22:46 +020032This command uses a binary search algorithm to find which commit in
33your project's history introduced a bug. You use it by first telling
34it a "bad" commit that is known to contain the bug, and a "good"
35commit that is known to be before the bug was introduced. Then `git
36bisect` picks a commit between those two endpoints and asks you
37whether the selected commit is "good" or "bad". It continues narrowing
38down the range until it finds the exact commit that introduced the
39change.
Junio C Hamano7fc9d692005-08-23 01:49:47 -070040
Antoine Delaite21e5cfd2015-06-29 17:40:33 +020041In fact, `git bisect` can be used to find the commit that changed
42*any* property of your project; e.g., the commit that fixed a bug, or
43the commit that caused a benchmark's performance to improve. To
44support this more general usage, the terms "old" and "new" can be used
Matthieu Moy06e6a742015-06-29 17:40:35 +020045in place of "good" and "bad", or you can choose your own terms. See
Antoine Delaite21e5cfd2015-06-29 17:40:33 +020046section "Alternate terms" below for more information.
47
Christian Couder1207f9e2007-03-24 06:30:33 +010048Basic bisect commands: start, bad, good
49~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50
Michael Haggerty2df5a842015-06-26 22:22:46 +020051As an example, suppose you are trying to find the commit that broke a
52feature that was known to work in version `v2.6.13-rc2` of your
53project. You start a bisect session as follows:
Junio C Hamano7fc9d692005-08-23 01:49:47 -070054
Junio C Hamanof85a4192005-08-29 17:21:06 -070055------------------------------------------------
Junio C Hamano556cb4e2005-12-05 00:15:24 -080056$ git bisect start
Christian Couder6cea0552007-03-24 06:32:05 +010057$ git bisect bad # Current version is bad
Michael Haggerty2df5a842015-06-26 22:22:46 +020058$ git bisect good v2.6.13-rc2 # v2.6.13-rc2 is known to be good
Junio C Hamanof85a4192005-08-29 17:21:06 -070059------------------------------------------------
Junio C Hamano7fc9d692005-08-23 01:49:47 -070060
Michael Haggerty2df5a842015-06-26 22:22:46 +020061Once you have specified at least one bad and one good commit, `git
62bisect` selects a commit in the middle of that range of history,
63checks it out, and outputs something similar to the following:
Junio C Hamanof85a4192005-08-29 17:21:06 -070064
65------------------------------------------------
Michael Haggerty2df5a842015-06-26 22:22:46 +020066Bisecting: 675 revisions left to test after this (roughly 10 steps)
Junio C Hamanof85a4192005-08-29 17:21:06 -070067------------------------------------------------
68
Michael Haggerty2df5a842015-06-26 22:22:46 +020069You should now compile the checked-out version and test it. If that
70version works correctly, type
Junio C Hamanof85a4192005-08-29 17:21:06 -070071
72------------------------------------------------
Michael Haggerty2df5a842015-06-26 22:22:46 +020073$ git bisect good
Junio C Hamanof85a4192005-08-29 17:21:06 -070074------------------------------------------------
75
Michael Haggerty2df5a842015-06-26 22:22:46 +020076If that version is broken, type
Junio C Hamanof85a4192005-08-29 17:21:06 -070077
78------------------------------------------------
Michael Haggerty2df5a842015-06-26 22:22:46 +020079$ git bisect bad
Junio C Hamanof85a4192005-08-29 17:21:06 -070080------------------------------------------------
81
Michael Haggerty2df5a842015-06-26 22:22:46 +020082Then `git bisect` will respond with something like
Junio C Hamanof85a4192005-08-29 17:21:06 -070083
Michael Haggerty2df5a842015-06-26 22:22:46 +020084------------------------------------------------
85Bisecting: 337 revisions left to test after this (roughly 9 steps)
86------------------------------------------------
87
88Keep repeating the process: compile the tree, test it, and depending
89on whether it is good or bad run `git bisect good` or `git bisect bad`
90to ask for the next commit that needs testing.
91
92Eventually there will be no more revisions left to inspect, and the
93command will print out a description of the first bad commit. The
94reference `refs/bisect/bad` will be left pointing at that commit.
95
Junio C Hamanof85a4192005-08-29 17:21:06 -070096
Christian Couder1207f9e2007-03-24 06:30:33 +010097Bisect reset
98~~~~~~~~~~~~
99
Anders Kaseorg6b87ce22009-10-13 17:02:24 -0400100After a bisect session, to clean up the bisection state and return to
Michael Haggerty2df5a842015-06-26 22:22:46 +0200101the original HEAD, issue the following command:
Junio C Hamanof85a4192005-08-29 17:21:06 -0700102
103------------------------------------------------
Junio C Hamano556cb4e2005-12-05 00:15:24 -0800104$ git bisect reset
Junio C Hamanof85a4192005-08-29 17:21:06 -0700105------------------------------------------------
106
Anders Kaseorg6b87ce22009-10-13 17:02:24 -0400107By default, this will return your tree to the commit that was checked
108out before `git bisect start`. (A new `git bisect start` will also do
109that, as it cleans up the old bisection state.)
110
111With an optional argument, you can return to a different commit
112instead:
113
114------------------------------------------------
115$ git bisect reset <commit>
116------------------------------------------------
117
Michael Haggerty2df5a842015-06-26 22:22:46 +0200118For example, `git bisect reset bisect/bad` will check out the first
119bad revision, while `git bisect reset HEAD` will leave you on the
120current bisection commit and avoid switching commits at all.
121
Junio C Hamano7fc9d692005-08-23 01:49:47 -0700122
Antoine Delaite21e5cfd2015-06-29 17:40:33 +0200123Alternate terms
124~~~~~~~~~~~~~~~
125
126Sometimes you are not looking for the commit that introduced a
127breakage, but rather for a commit that caused a change between some
128other "old" state and "new" state. For example, you might be looking
129for the commit that introduced a particular fix. Or you might be
130looking for the first commit in which the source-code filenames were
131finally all converted to your company's naming standard. Or whatever.
132
133In such cases it can be very confusing to use the terms "good" and
134"bad" to refer to "the state before the change" and "the state after
135the change". So instead, you can use the terms "old" and "new",
136respectively, in place of "good" and "bad". (But note that you cannot
137mix "good" and "bad" with "old" and "new" in a single session.)
138
139In this more general usage, you provide `git bisect` with a "new"
Quentin Pradet60b091c2017-04-01 10:40:56 +0400140commit that has some property and an "old" commit that doesn't have that
Antoine Delaite21e5cfd2015-06-29 17:40:33 +0200141property. Each time `git bisect` checks out a commit, you test if that
142commit has the property. If it does, mark the commit as "new";
143otherwise, mark it as "old". When the bisection is done, `git bisect`
144will report which commit introduced the property.
145
146To use "old" and "new" instead of "good" and bad, you must run `git
147bisect start` without commits as argument and then run the following
148commands to add the commits:
149
150------------------------------------------------
151git bisect old [<rev>]
152------------------------------------------------
153
154to indicate that a commit was before the sought change, or
155
156------------------------------------------------
157git bisect new [<rev>...]
158------------------------------------------------
159
160to indicate that it was after.
161
Matthieu Moy21b55e32015-06-29 17:40:34 +0200162To get a reminder of the currently used terms, use
163
164------------------------------------------------
165git bisect terms
166------------------------------------------------
167
Anders Kaseorgbbd374d2018-04-06 16:21:19 -0400168You can get just the old (respectively new) term with `git bisect terms
169--term-old` or `git bisect terms --term-good`.
Matthieu Moy21b55e32015-06-29 17:40:34 +0200170
Matthieu Moy06e6a742015-06-29 17:40:35 +0200171If you would like to use your own terms instead of "bad"/"good" or
172"new"/"old", you can choose any names you like (except existing bisect
173subcommands like `reset`, `start`, ...) by starting the
174bisection using
175
176------------------------------------------------
177git bisect start --term-old <term-old> --term-new <term-new>
178------------------------------------------------
179
180For example, if you are looking for a commit that introduced a
181performance regression, you might use
182
183------------------------------------------------
184git bisect start --term-old fast --term-new slow
185------------------------------------------------
186
187Or if you are looking for the commit that fixed a bug, you might use
188
189------------------------------------------------
190git bisect start --term-new fixed --term-old broken
191------------------------------------------------
192
193Then, use `git bisect <term-old>` and `git bisect <term-new>` instead
194of `git bisect good` and `git bisect bad` to mark commits.
195
Robert P. J. Daydbc349b2017-11-12 04:30:38 -0500196Bisect visualize/view
197~~~~~~~~~~~~~~~~~~~~~
Christian Couder1207f9e2007-03-24 06:30:33 +0100198
David J. Mellora42dea32009-03-22 20:11:10 -0700199To see the currently remaining suspects in 'gitk', issue the following
Robert P. J. Daydbc349b2017-11-12 04:30:38 -0500200command during the bisection process (the subcommand `view` can be used
201as an alternative to `visualize`):
Junio C Hamano8db93072005-08-30 13:51:01 -0700202
Junio C Hamano556cb4e2005-12-05 00:15:24 -0800203------------
204$ git bisect visualize
205------------
Junio C Hamano8db93072005-08-30 13:51:01 -0700206
Tom Russello47d81b52016-06-08 00:35:07 +0200207If the `DISPLAY` environment variable is not set, 'git log' is used
Jason St. John06ab60c2014-05-21 14:52:26 -0400208instead. You can also give command-line options such as `-p` and
Junio C Hamano235997c2007-12-07 02:25:34 -0800209`--stat`.
210
211------------
Robert P. J. Daydbc349b2017-11-12 04:30:38 -0500212$ git bisect visualize --stat
Junio C Hamano235997c2007-12-07 02:25:34 -0800213------------
Junio C Hamano8db93072005-08-30 13:51:01 -0700214
Christian Couder1207f9e2007-03-24 06:30:33 +0100215Bisect log and bisect replay
216~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217
David J. Mellora42dea32009-03-22 20:11:10 -0700218After having marked revisions as good or bad, issue the following
David J. Mellor4306bcb2009-03-19 20:35:34 -0700219command to show what has been done so far:
Christian Couderfed820a2007-03-24 06:31:49 +0100220
221------------
222$ git bisect log
223------------
224
David J. Mellor4306bcb2009-03-19 20:35:34 -0700225If you discover that you made a mistake in specifying the status of a
226revision, you can save the output of this command to a file, edit it to
227remove the incorrect entries, and then issue the following commands to
228return to a corrected state:
Junio C Hamanob595ed12005-09-10 15:23:09 -0700229
Junio C Hamano556cb4e2005-12-05 00:15:24 -0800230------------
David J. Melloree9cf142009-03-19 00:00:12 -0700231$ git bisect reset
Junio C Hamano556cb4e2005-12-05 00:15:24 -0800232$ git bisect replay that-file
233------------
Junio C Hamanob595ed12005-09-10 15:23:09 -0700234
David J. Mellor23642592009-03-16 23:16:15 -0700235Avoiding testing a commit
Christian Couder1207f9e2007-03-24 06:30:33 +0100236~~~~~~~~~~~~~~~~~~~~~~~~~
237
Michael Haggerty2df5a842015-06-26 22:22:46 +0200238If, in the middle of a bisect session, you know that the suggested
239revision is not a good one to test (e.g. it fails to build and you
240know that the failure does not have anything to do with the bug you
241are chasing), you can manually select a nearby commit and test that
242one instead.
Christian Couderfed820a2007-03-24 06:31:49 +0100243
David J. Mellor23642592009-03-16 23:16:15 -0700244For example:
Junio C Hamano556cb4e2005-12-05 00:15:24 -0800245
246------------
David J. Melloree9cf142009-03-19 00:00:12 -0700247$ git bisect good/bad # previous round was good or bad.
Michael Haggerty2df5a842015-06-26 22:22:46 +0200248Bisecting: 337 revisions left to test after this (roughly 9 steps)
Junio C Hamano556cb4e2005-12-05 00:15:24 -0800249$ git bisect visualize # oops, that is uninteresting.
David J. Mellor23642592009-03-16 23:16:15 -0700250$ git reset --hard HEAD~3 # try 3 revisions before what
Junio C Hamano556cb4e2005-12-05 00:15:24 -0800251 # was suggested
252------------
253
David J. Mellor19fa5e82009-03-25 20:44:44 -0700254Then compile and test the chosen revision, and afterwards mark
David J. Mellora42dea32009-03-22 20:11:10 -0700255the revision as good or bad in the usual manner.
Junio C Hamano556cb4e2005-12-05 00:15:24 -0800256
Christian Couderc39ce912007-10-22 07:49:23 +0200257Bisect skip
Junio C Hamano142d0352015-10-22 10:09:07 -0700258~~~~~~~~~~~
Christian Couderc39ce912007-10-22 07:49:23 +0200259
Michael Haggerty2df5a842015-06-26 22:22:46 +0200260Instead of choosing a nearby commit by yourself, you can ask Git to do
261it for you by issuing the command:
Christian Couderc39ce912007-10-22 07:49:23 +0200262
263------------
264$ git bisect skip # Current version cannot be tested
265------------
266
Michael Haggerty2df5a842015-06-26 22:22:46 +0200267However, if you skip a commit adjacent to the one you are looking for,
268Git will be unable to tell exactly which of those commits was the
269first bad one.
Christian Couderc39ce912007-10-22 07:49:23 +0200270
Michael Haggerty2df5a842015-06-26 22:22:46 +0200271You can also skip a range of commits, instead of just one commit,
272using range notation. For example:
Christian Couder54138122008-12-02 14:53:51 +0100273
274------------
275$ git bisect skip v2.5..v2.6
276------------
277
David J. Mellor19fa5e82009-03-25 20:44:44 -0700278This tells the bisect process that no commit after `v2.5`, up to and
279including `v2.6`, should be tested.
Christian Couder54138122008-12-02 14:53:51 +0100280
David J. Mellor23642592009-03-16 23:16:15 -0700281Note that if you also want to skip the first commit of the range you
282would issue the command:
Christian Couder54138122008-12-02 14:53:51 +0100283
284------------
285$ git bisect skip v2.5 v2.5..v2.6
286------------
287
Michael Haggerty2df5a842015-06-26 22:22:46 +0200288This tells the bisect process that the commits between `v2.5` and
289`v2.6` (inclusive) should be skipped.
David J. Mellor4306bcb2009-03-19 20:35:34 -0700290
Christian Couder54138122008-12-02 14:53:51 +0100291
Christian Couder6fe9c572007-04-05 05:33:53 +0200292Cutting down bisection by giving more parameters to bisect start
293~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Christian Couder1207f9e2007-03-24 06:30:33 +0100294
David J. Mellor23642592009-03-16 23:16:15 -0700295You can further cut down the number of trials, if you know what part of
296the tree is involved in the problem you are tracking down, by specifying
David J. Mellor4306bcb2009-03-19 20:35:34 -0700297path parameters when issuing the `bisect start` command:
Junio C Hamano556cb4e2005-12-05 00:15:24 -0800298
299------------
Christian Couder6fe9c572007-04-05 05:33:53 +0200300$ git bisect start -- arch/i386 include/asm-i386
301------------
302
David J. Mellor23642592009-03-16 23:16:15 -0700303If you know beforehand more than one good commit, you can narrow the
304bisect space down by specifying all of the good commits immediately after
305the bad commit when issuing the `bisect start` command:
Christian Couder6fe9c572007-04-05 05:33:53 +0200306
307------------
308$ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --
309 # v2.6.20-rc6 is bad
310 # v2.6.20-rc4 and v2.6.20-rc1 are good
Junio C Hamano556cb4e2005-12-05 00:15:24 -0800311------------
312
Christian Couder1207f9e2007-03-24 06:30:33 +0100313Bisect run
314~~~~~~~~~~
315
Christian Couder7891a282007-03-24 06:29:58 +0100316If you have a script that can tell if the current source code is good
David J. Mellor23642592009-03-16 23:16:15 -0700317or bad, you can bisect by issuing the command:
Christian Coudera17c4102007-03-23 08:49:59 +0100318
319------------
John Tapsellfad5c962009-03-05 12:36:14 +0000320$ git bisect run my_script arguments
Christian Coudera17c4102007-03-23 08:49:59 +0100321------------
322
Michael Haggerty2df5a842015-06-26 22:22:46 +0200323Note that the script (`my_script` in the above example) should exit
324with code 0 if the current source code is good/old, and exit with a
325code between 1 and 127 (inclusive), except 125, if the current source
326code is bad/new.
Christian Coudera17c4102007-03-23 08:49:59 +0100327
David J. Mellor23642592009-03-16 23:16:15 -0700328Any other exit code will abort the bisect process. It should be noted
Michael Haggerty2df5a842015-06-26 22:22:46 +0200329that a program that terminates via `exit(-1)` leaves $? = 255, (see the
330exit(3) manual page), as the value is chopped with `& 0377`.
Christian Coudera17c4102007-03-23 08:49:59 +0100331
Christian Couder71b02512007-10-26 05:39:37 +0200332The special exit code 125 should be used when the current source code
David J. Mellor23642592009-03-16 23:16:15 -0700333cannot be tested. If the script exits with this code, the current
Junio C Hamano958bf6b2011-03-19 21:46:06 -0700334revision will be skipped (see `git bisect skip` above). 125 was chosen
335as the highest sensible value to use for this purpose, because 126 and 127
336are used by POSIX shells to signal specific error status (127 is for
Junio C Hamano3b19dba2015-10-22 13:02:33 -0700337command not found, 126 is for command found but not executable--these
Junio C Hamano958bf6b2011-03-19 21:46:06 -0700338details do not matter, as they are normal errors in the script, as far as
Michael Haggerty2df5a842015-06-26 22:22:46 +0200339`bisect run` is concerned).
Christian Couder71b02512007-10-26 05:39:37 +0200340
David J. Mellor23642592009-03-16 23:16:15 -0700341You may often find that during a bisect session you want to have
342temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a
343header file, or "revision that does not have this commit needs this
344patch applied to work around another problem this bisection is not
345interested in") applied to the revision being tested.
Christian Coudera17c4102007-03-23 08:49:59 +0100346
Christian Couder5bcce842008-11-09 14:53:14 +0100347To cope with such a situation, after the inner 'git bisect' finds the
David J. Mellor23642592009-03-16 23:16:15 -0700348next revision to test, the script can apply the patch
349before compiling, run the real test, and afterwards decide if the
350revision (possibly with the needed patch) passed the test and then
351rewind the tree to the pristine state. Finally the script should exit
Michael Haggerty2df5a842015-06-26 22:22:46 +0200352with the status of the real test to let the `git bisect run` command loop
David J. Melloree9cf142009-03-19 00:00:12 -0700353determine the eventual outcome of the bisect session.
Junio C Hamano7fc9d692005-08-23 01:49:47 -0700354
Jon Seymour88d78912011-08-04 22:01:03 +1000355OPTIONS
356-------
357--no-checkout::
358+
359Do not checkout the new working tree at each iteration of the bisection
Matthieu Moy661c3e92016-06-28 13:40:15 +0200360process. Instead just update a special reference named `BISECT_HEAD` to make
Jon Seymour88d78912011-08-04 22:01:03 +1000361it point to the commit that should be tested.
362+
363This option may be useful when the test you would perform in each step
364does not require a checked out tree.
Jon Seymour24c51282011-08-09 12:11:54 +1000365+
366If the repository is bare, `--no-checkout` is assumed.
Jon Seymour88d78912011-08-04 22:01:03 +1000367
Christian Couderbac59f12008-05-08 01:00:54 +0200368EXAMPLES
369--------
370
371* Automatically bisect a broken build between v1.2 and HEAD:
372+
373------------
374$ git bisect start HEAD v1.2 -- # HEAD is bad, v1.2 is good
375$ git bisect run make # "make" builds the app
Michael J Gruberc787a452013-02-11 09:35:04 +0100376$ git bisect reset # quit the bisect session
Christian Couderbac59f12008-05-08 01:00:54 +0200377------------
378
John Tapsellfad5c962009-03-05 12:36:14 +0000379* Automatically bisect a test failure between origin and HEAD:
380+
381------------
382$ git bisect start HEAD origin -- # HEAD is bad, origin is good
383$ git bisect run make test # "make test" builds and tests
Michael J Gruberc787a452013-02-11 09:35:04 +0100384$ git bisect reset # quit the bisect session
John Tapsellfad5c962009-03-05 12:36:14 +0000385------------
386
Christian Couderbac59f12008-05-08 01:00:54 +0200387* Automatically bisect a broken test case:
388+
389------------
390$ cat ~/test.sh
391#!/bin/sh
David J. Mellor23642592009-03-16 23:16:15 -0700392make || exit 125 # this skips broken builds
Michael J Gruber9d79b7e2011-03-15 22:24:55 +0100393~/check_test_case.sh # does the test case pass?
Christian Couderbac59f12008-05-08 01:00:54 +0200394$ git bisect start HEAD HEAD~10 -- # culprit is among the last 10
395$ git bisect run ~/test.sh
Michael J Gruberc787a452013-02-11 09:35:04 +0100396$ git bisect reset # quit the bisect session
Christian Couderbac59f12008-05-08 01:00:54 +0200397------------
398+
Michael Haggerty2df5a842015-06-26 22:22:46 +0200399Here we use a `test.sh` custom script. In this script, if `make`
Michael J Gruber9d79b7e2011-03-15 22:24:55 +0100400fails, we skip the current commit.
Michael Haggerty2df5a842015-06-26 22:22:46 +0200401`check_test_case.sh` should `exit 0` if the test case passes,
402and `exit 1` otherwise.
Christian Couderbac59f12008-05-08 01:00:54 +0200403+
Michael Haggerty2df5a842015-06-26 22:22:46 +0200404It is safer if both `test.sh` and `check_test_case.sh` are
David J. Mellor23642592009-03-16 23:16:15 -0700405outside the repository to prevent interactions between the bisect,
406make and test processes and the scripts.
Christian Couderbac59f12008-05-08 01:00:54 +0200407
Michael J Grubere235b912011-03-15 22:24:56 +0100408* Automatically bisect with temporary modifications (hot-fix):
409+
410------------
411$ cat ~/test.sh
412#!/bin/sh
413
414# tweak the working tree by merging the hot-fix branch
415# and then attempt a build
416if git merge --no-commit hot-fix &&
417 make
418then
419 # run project specific test and report its status
420 ~/check_test_case.sh
421 status=$?
422else
423 # tell the caller this is untestable
424 status=125
425fi
426
427# undo the tweak to allow clean flipping to the next commit
428git reset --hard
429
430# return control
431exit $status
432------------
433+
434This applies modifications from a hot-fix branch before each test run,
435e.g. in case your build or test environment changed so that older
436revisions may need a fix which newer ones have already. (Make sure the
437hot-fix branch is based off a commit which is contained in all revisions
438which you are bisecting, so that the merge does not pull in too much, or
439use `git cherry-pick` instead of `git merge`.)
440
Michael J Gruber9d79b7e2011-03-15 22:24:55 +0100441* Automatically bisect a broken test case:
John Tapsellfad5c962009-03-05 12:36:14 +0000442+
443------------
444$ git bisect start HEAD HEAD~10 -- # culprit is among the last 10
445$ git bisect run sh -c "make || exit 125; ~/check_test_case.sh"
Michael J Gruberc787a452013-02-11 09:35:04 +0100446$ git bisect reset # quit the bisect session
John Tapsellfad5c962009-03-05 12:36:14 +0000447------------
448+
Michael J Gruber9d79b7e2011-03-15 22:24:55 +0100449This shows that you can do without a run script if you write the test
450on a single line.
John Tapsellfad5c962009-03-05 12:36:14 +0000451
Jon Seymour88d78912011-08-04 22:01:03 +1000452* Locate a good region of the object graph in a damaged repository
453+
454------------
455$ git bisect start HEAD <known-good-commit> [ <boundary-commit> ... ] --no-checkout
456$ git bisect run sh -c '
457 GOOD=$(git for-each-ref "--format=%(objectname)" refs/bisect/good-*) &&
458 git rev-list --objects BISECT_HEAD --not $GOOD >tmp.$$ &&
459 git pack-objects --stdout >/dev/null <tmp.$$
460 rc=$?
461 rm -f tmp.$$
462 test $rc = 0'
463
Michael J Gruberc787a452013-02-11 09:35:04 +0100464$ git bisect reset # quit the bisect session
Jon Seymour88d78912011-08-04 22:01:03 +1000465------------
466+
467In this case, when 'git bisect run' finishes, bisect/bad will refer to a commit that
468has at least one parent whose reachable graph is fully traversable in the sense
469required by 'git pack objects'.
470
Antoine Delaite21e5cfd2015-06-29 17:40:33 +0200471* Look for a fix instead of a regression in the code
472+
473------------
474$ git bisect start
475$ git bisect new HEAD # current commit is marked as new
476$ git bisect old HEAD~10 # the tenth commit from now is marked as old
477------------
Matthieu Moy06e6a742015-06-29 17:40:35 +0200478+
479or:
480------------
481$ git bisect start --term-old broken --term-new fixed
482$ git bisect fixed
483$ git bisect broken HEAD~10
484------------
Antoine Delaite21e5cfd2015-06-29 17:40:33 +0200485
Matthieu Moyc9493972015-06-26 18:58:11 +0200486Getting help
487~~~~~~~~~~~~
488
489Use `git bisect` to get a short usage description, and `git bisect
490help` or `git bisect -h` to get a long usage description.
Jon Seymour88d78912011-08-04 22:01:03 +1000491
Christian Couder69a9cd32009-11-08 16:09:47 +0100492SEE ALSO
493--------
494link:git-bisect-lk2009.html[Fighting regressions with git bisect],
495linkgit:git-blame[1].
496
Junio C Hamano7fc9d692005-08-23 01:49:47 -0700497GIT
498---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200499Part of the linkgit:git[1] suite