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).
204
205       You may often find that during a bisect session you want to have
206       temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a
207       header file, or "revision that does not have this commit needs this
208       patch applied to work around another problem this bisection is not
209       interested in") applied to the revision being tested.
210
211       To cope with such a situation, after the inner git bisect finds the
212       next revision to test, the script can apply the patch before compiling,
213       run the real test, and afterwards decide if the revision (possibly with
214       the needed patch) passed the test and then rewind the tree to the
215       pristine state. Finally the script should exit with the status of the
216       real test to let the "git bisect run" command loop determine the
217       eventual outcome of the bisect session.
218

EXAMPLES

220       ·   Automatically bisect a broken build between v1.2 and HEAD:
221
222               $ git bisect start HEAD v1.2 --      # HEAD is bad, v1.2 is good
223               $ git bisect run make                # "make" builds the app
224
225
226       ·   Automatically bisect a test failure between origin and HEAD:
227
228               $ git bisect start HEAD origin --    # HEAD is bad, origin is good
229               $ git bisect run make test           # "make test" builds and tests
230
231
232       ·   Automatically bisect a broken test suite:
233
234               $ cat ~/test.sh
235               #!/bin/sh
236               make || exit 125                   # this skips broken builds
237               make test                          # "make test" runs the test suite
238               $ git bisect start v1.3 v1.1 --    # v1.3 is bad, v1.1 is good
239               $ git bisect run ~/test.sh
240
241           Here we use a "test.sh" custom script. In this script, if "make"
242           fails, we skip the current commit.
243
244           It is safer to use a custom script outside the repository to
245           prevent interactions between the bisect, make and test processes
246           and the script.
247
248           "make test" should "exit 0", if the test suite passes, and "exit 1"
249           otherwise.
250
251       ·   Automatically bisect a broken test case:
252
253               $ cat ~/test.sh
254               #!/bin/sh
255               make || exit 125                     # this skips broken builds
256               ~/check_test_case.sh                 # does the test case passes ?
257               $ git bisect start HEAD HEAD~10 --   # culprit is among the last 10
258               $ git bisect run ~/test.sh
259
260           Here "check_test_case.sh" should "exit 0" if the test case passes,
261           and "exit 1" otherwise.
262
263           It is safer if both "test.sh" and "check_test_case.sh" scripts are
264           outside the repository to prevent interactions between the bisect,
265           make and test processes and the scripts.
266
267       ·   Automatically bisect a broken test suite:
268
269               $ git bisect start HEAD HEAD~10 --   # culprit is among the last 10
270               $ git bisect run sh -c "make || exit 125; ~/check_test_case.sh"
271
272           Does the same as the previous example, but on a single line.
273

AUTHOR

275       Written by Linus Torvalds <torvalds@osdl.org[1]>
276

DOCUMENTATION

278       Documentation by Junio C Hamano and the git-list
279       <git@vger.kernel.org[2]>.
280

SEE ALSO

282       Fighting regressions with git bisect[3], git-blame(1).
283

GIT

285       Part of the git(1) suite
286

NOTES

288        1. torvalds@osdl.org
289           mailto:torvalds@osdl.org
290
291        2. git@vger.kernel.org
292           mailto:git@vger.kernel.org
293
294        3. Fighting regressions with git bisect
295           file:///usr/share/doc/git-1.7.1/git-bisect-lk2009.html
296
297
298
299Git 1.7.1                         08/16/2017                     GIT-BISECT(1)
Impressum