1GIT-BISECT(1)                     Git Manual                     GIT-BISECT(1)
2
3
4

NAME

6       git-bisect - Find by binary search the change that introduced a bug
7

SYNOPSIS

9       git bisect <subcommand> <options>
10

DESCRIPTION

12       The command takes various subcommands, and different options depending
13       on the subcommand:
14
15           git bisect help
16           git bisect start [<bad> [<good>...]] [--] [<paths>...]
17           git bisect bad [<rev>]
18           git bisect good [<rev>...]
19           git bisect skip [(<rev>|<range>)...]
20           git bisect reset [<commit>]
21           git bisect visualize
22           git bisect replay <logfile>
23           git bisect log
24           git bisect run <cmd>...
25
26       This command uses git rev-list --bisect to help drive the binary search
27       process to find which change introduced a bug, given an old "good"
28       commit object name and a later "bad" commit object name.
29
30   Getting help
31       Use "git bisect" to get a short usage description, and "git bisect
32       help" or "git bisect -h" to get a long usage description.
33
34   Basic bisect commands: start, bad, good
35       Using the Linux kernel tree as an example, basic use of the bisect
36       command is as follows:
37
38           $ git bisect start
39           $ git bisect bad                 # Current version is bad
40           $ git bisect good v2.6.13-rc2    # v2.6.13-rc2 was the last version
41                                            # tested that was good
42
43
44       When you have specified at least one bad and one good version, the
45       command bisects the revision tree and outputs something similar to the
46       following:
47
48           Bisecting: 675 revisions left to test after this
49
50
51       The state in the middle of the set of revisions is then checked out.
52       You would now compile that kernel and boot it. If the booted kernel
53       works correctly, you would then issue the following command:
54
55           $ git bisect good                       # this one is good
56
57
58       The output of this command would be something similar to the following:
59
60           Bisecting: 337 revisions left to test after this
61
62
63       You keep repeating this process, compiling the tree, testing it, and
64       depending on whether it is good or bad issuing the command "git bisect
65       good" or "git bisect bad" to ask for the next bisection.
66
67       Eventually there will be no more revisions left to bisect, and you will
68       have been left with the first bad kernel revision in "refs/bisect/bad".
69
70   Bisect reset
71       After a bisect session, to clean up the bisection state and return to
72       the original HEAD, issue the following command:
73
74           $ git bisect reset
75
76
77       By default, this will return your tree to the commit that was checked
78       out before git bisect start. (A new git bisect start will also do that,
79       as it cleans up the old bisection state.)
80
81       With an optional argument, you can return to a different commit
82       instead:
83
84           $ git bisect reset <commit>
85
86
87       For example, git bisect reset HEAD will leave you on the current
88       bisection commit and avoid switching commits at all, while git bisect
89       reset bisect/bad will check out the first bad revision.
90
91   Bisect visualize
92       To see the currently remaining suspects in gitk, issue the following
93       command during the bisection process:
94
95           $ git bisect visualize
96
97
98       view may also be used as a synonym for visualize.
99
100       If the DISPLAY environment variable is not set, git log is used
101       instead. You can also give command line options such as -p and --stat.
102
103           $ git bisect view --stat
104
105
106   Bisect log and bisect replay
107       After having marked revisions as good or bad, issue the following
108       command to show what has been done so far:
109
110           $ git bisect log
111
112
113       If you discover that you made a mistake in specifying the status of a
114       revision, you can save the output of this command to a file, edit it to
115       remove the incorrect entries, and then issue the following commands to
116       return to a corrected state:
117
118           $ git bisect reset
119           $ git bisect replay that-file
120
121
122   Avoiding testing a commit
123       If, in the middle of a bisect session, you know that the next suggested
124       revision is not a good one to test (e.g. the change the commit
125       introduces is known not to work in your environment and you know it
126       does not have anything to do with the bug you are chasing), you may
127       want to find a nearby commit and try that instead.
128
129       For example:
130
131           $ git bisect good/bad                   # previous round was good or bad.
132           Bisecting: 337 revisions left to test after this
133           $ git bisect visualize                  # oops, that is uninteresting.
134           $ git reset --hard HEAD~3               # try 3 revisions before what
135                                                   # was suggested
136
137
138       Then compile and test the chosen revision, and afterwards mark the
139       revision as good or bad in the usual manner.
140
141   Bisect skip
142       Instead of choosing by yourself a nearby commit, you can ask git to do
143       it for you by issuing the command:
144
145           $ git bisect skip                 # Current version cannot be tested
146
147
148       But git may eventually be unable to tell the first bad commit among a
149       bad commit and one or more skipped commits.
150
151       You can even skip a range of commits, instead of just one commit, using
152       the "<commit1>..<commit2>" notation. For example:
153
154           $ git bisect skip v2.5..v2.6
155
156
157       This tells the bisect process that no commit after v2.5, up to and
158       including v2.6, should be tested.
159
160       Note that if you also want to skip the first commit of the range you
161       would issue the command:
162
163           $ git bisect skip v2.5 v2.5..v2.6
164
165
166       This tells the bisect process that the commits between v2.5 included
167       and v2.6 included should be skipped.
168
169   Cutting down bisection by giving more parameters to bisect start
170       You can further cut down the number of trials, if you know what part of
171       the tree is involved in the problem you are tracking down, by
172       specifying path parameters when issuing the bisect start command:
173
174           $ git bisect start -- arch/i386 include/asm-i386
175
176
177       If you know beforehand more than one good commit, you can narrow the
178       bisect space down by specifying all of the good commits immediately
179       after the bad commit when issuing the bisect start command:
180
181           $ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --
182                              # v2.6.20-rc6 is bad
183                              # v2.6.20-rc4 and v2.6.20-rc1 are good
184
185
186   Bisect run
187       If you have a script that can tell if the current source code is good
188       or bad, you can bisect by issuing the command:
189
190           $ git bisect run my_script arguments
191
192
193       Note that the script (my_script in the above example) should exit with
194       code 0 if the current source code is good, and exit with a code between
195       1 and 127 (inclusive), except 125, if the current source code is bad.
196
197       Any other exit code will abort the bisect process. It should be noted
198       that a program that terminates via "exit(-1)" leaves $? = 255, (see the
199       exit(3) manual page), as the value is chopped with "& 0377".
200
201       The special exit code 125 should be used when the current source code
202       cannot be tested. If the script exits with this code, the current
203       revision will be skipped (see git bisect skip above). 125 was chosen as
204       the highest sensible value to use for this purpose, because 126 and 127
205       are used by POSIX shells to signal specific error status (127 is for
206       command not found, 126 is for command found but not executable---these
207       details do not matter, as they are normal errors in the script, as far
208       as "bisect run" is concerned).
209
210       You may often find that during a bisect session you want to have
211       temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a
212       header file, or "revision that does not have this commit needs this
213       patch applied to work around another problem this bisection is not
214       interested in") applied to the revision being tested.
215
216       To cope with such a situation, after the inner git bisect finds the
217       next revision to test, the script can apply the patch before compiling,
218       run the real test, and afterwards decide if the revision (possibly with
219       the needed patch) passed the test and then rewind the tree to the
220       pristine state. Finally the script should exit with the status of the
221       real test to let the "git bisect run" command loop determine the
222       eventual outcome of the bisect session.
223

EXAMPLES

225       ·   Automatically bisect a broken build between v1.2 and HEAD:
226
227               $ git bisect start HEAD v1.2 --      # HEAD is bad, v1.2 is good
228               $ git bisect run make                # "make" builds the app
229
230
231       ·   Automatically bisect a test failure between origin and HEAD:
232
233               $ git bisect start HEAD origin --    # HEAD is bad, origin is good
234               $ git bisect run make test           # "make test" builds and tests
235
236
237       ·   Automatically bisect a broken test case:
238
239               $ cat ~/test.sh
240               #!/bin/sh
241               make || exit 125                     # this skips broken builds
242               ~/check_test_case.sh                 # does the test case pass?
243               $ git bisect start HEAD HEAD~10 --   # culprit is among the last 10
244               $ git bisect run ~/test.sh
245
246           Here we use a "test.sh" custom script. In this script, if "make"
247           fails, we skip the current commit. "check_test_case.sh" should
248           "exit 0" if the test case passes, and "exit 1" otherwise.
249
250           It is safer if both "test.sh" and "check_test_case.sh" are outside
251           the repository to prevent interactions between the bisect, make and
252           test processes and the scripts.
253
254       ·   Automatically bisect with temporary modifications (hot-fix):
255
256               $ cat ~/test.sh
257               #!/bin/sh
258
259               # tweak the working tree by merging the hot-fix branch
260               # and then attempt a build
261               if      git merge --no-commit hot-fix &&
262                       make
263               then
264                       # run project specific test and report its status
265                       ~/check_test_case.sh
266                       status=$?
267               else
268                       # tell the caller this is untestable
269                       status=125
270               fi
271
272               # undo the tweak to allow clean flipping to the next commit
273               git reset --hard
274
275               # return control
276               exit $status
277
278           This applies modifications from a hot-fix branch before each test
279           run, e.g. in case your build or test environment changed so that
280           older revisions may need a fix which newer ones have already. (Make
281           sure the hot-fix branch is based off a commit which is contained in
282           all revisions which you are bisecting, so that the merge does not
283           pull in too much, or use git cherry-pick instead of git merge.)
284
285       ·   Automatically bisect a broken test case:
286
287               $ git bisect start HEAD HEAD~10 --   # culprit is among the last 10
288               $ git bisect run sh -c "make || exit 125; ~/check_test_case.sh"
289
290           This shows that you can do without a run script if you write the
291           test on a single line.
292

AUTHOR

294       Written by Linus Torvalds <torvalds@osdl.org[1]>
295

DOCUMENTATION

297       Documentation by Junio C Hamano and the git-list
298       <git@vger.kernel.org[2]>.
299

SEE ALSO

301       Fighting regressions with git bisect[3], git-blame(1).
302

GIT

304       Part of the git(1) suite
305

NOTES

307        1. torvalds@osdl.org
308           mailto:torvalds@osdl.org
309
310        2. git@vger.kernel.org
311           mailto:git@vger.kernel.org
312
313        3. Fighting regressions with git bisect
314           file:///usr/share/doc/git-1.7.4.4/git-bisect-lk2009.html
315
316
317
318Git 1.7.4.4                       04/11/2011                     GIT-BISECT(1)
Impressum