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
11

DESCRIPTION

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

OPTIONS

227       --no-checkout
228           Do not checkout the new working tree at each iteration of the
229           bisection process. Instead just update a special reference named
230           BISECT_HEAD to make it point to the commit that should be tested.
231
232           This option may be useful when the test you would perform in each
233           step does not require a checked out tree.
234
235           If the repository is bare, --no-checkout is assumed.
236

EXAMPLES

238       ·   Automatically bisect a broken build between v1.2 and HEAD:
239
240               $ git bisect start HEAD v1.2 --      # HEAD is bad, v1.2 is good
241               $ git bisect run make                # "make" builds the app
242               $ git bisect reset                   # quit the bisect session
243
244
245       ·   Automatically bisect a test failure between origin and HEAD:
246
247               $ git bisect start HEAD origin --    # HEAD is bad, origin is good
248               $ git bisect run make test           # "make test" builds and tests
249               $ git bisect reset                   # quit the bisect session
250
251
252       ·   Automatically bisect a broken test case:
253
254               $ cat ~/test.sh
255               #!/bin/sh
256               make || exit 125                     # this skips broken builds
257               ~/check_test_case.sh                 # does the test case pass?
258               $ git bisect start HEAD HEAD~10 --   # culprit is among the last 10
259               $ git bisect run ~/test.sh
260               $ git bisect reset                   # quit the bisect session
261
262           Here we use a "test.sh" custom script. In this script, if "make"
263           fails, we skip the current commit. "check_test_case.sh" should
264           "exit 0" if the test case passes, and "exit 1" otherwise.
265
266           It is safer if both "test.sh" and "check_test_case.sh" are outside
267           the repository to prevent interactions between the bisect, make and
268           test processes and the scripts.
269
270       ·   Automatically bisect with temporary modifications (hot-fix):
271
272               $ cat ~/test.sh
273               #!/bin/sh
274
275               # tweak the working tree by merging the hot-fix branch
276               # and then attempt a build
277               if      git merge --no-commit hot-fix &&
278                       make
279               then
280                       # run project specific test and report its status
281                       ~/check_test_case.sh
282                       status=$?
283               else
284                       # tell the caller this is untestable
285                       status=125
286               fi
287
288               # undo the tweak to allow clean flipping to the next commit
289               git reset --hard
290
291               # return control
292               exit $status
293
294           This applies modifications from a hot-fix branch before each test
295           run, e.g. in case your build or test environment changed so that
296           older revisions may need a fix which newer ones have already. (Make
297           sure the hot-fix branch is based off a commit which is contained in
298           all revisions which you are bisecting, so that the merge does not
299           pull in too much, or use git cherry-pick instead of git merge.)
300
301       ·   Automatically bisect a broken test case:
302
303               $ git bisect start HEAD HEAD~10 --   # culprit is among the last 10
304               $ git bisect run sh -c "make || exit 125; ~/check_test_case.sh"
305               $ git bisect reset                   # quit the bisect session
306
307           This shows that you can do without a run script if you write the
308           test on a single line.
309
310       ·   Locate a good region of the object graph in a damaged repository
311
312               $ git bisect start HEAD <known-good-commit> [ <boundary-commit> ... ] --no-checkout
313               $ git bisect run sh -c '
314                       GOOD=$(git for-each-ref "--format=%(objectname)" refs/bisect/good-*) &&
315                       git rev-list --objects BISECT_HEAD --not $GOOD >tmp.$$ &&
316                       git pack-objects --stdout >/dev/null <tmp.$$
317                       rc=$?
318                       rm -f tmp.$$
319                       test $rc = 0'
320
321               $ git bisect reset                   # quit the bisect session
322
323           In this case, when git bisect run finishes, bisect/bad will refer
324           to a commit that has at least one parent whose reachable graph is
325           fully traversable in the sense required by git pack objects.
326

SEE ALSO

328       Fighting regressions with git bisect[1], git-blame(1).
329

GIT

331       Part of the git(1) suite
332

NOTES

334        1. Fighting regressions with git bisect
335           file:///usr/share/doc/git-1.8.3.1/git-bisect-lk2009.html
336
337
338
339Git 1.8.3.1                       11/19/2018                     GIT-BISECT(1)
Impressum