@@ -3,7 +3,7 @@ git-bisect(1)
3
3
4
4
NAME
5
5
----
6
- git-bisect - Find by binary search the change that introduced a bug
6
+ git-bisect - Use binary search to find the commit that introduced a bug
7
7
8
8
9
9
SYNOPSIS
@@ -16,7 +16,6 @@ DESCRIPTION
16
16
The command takes various subcommands, and different options depending
17
17
on the subcommand:
18
18
19
- git bisect help
20
19
git bisect start [--no-checkout] [<bad> [<good>...]] [--] [<paths>...]
21
20
git bisect bad [<rev>]
22
21
git bisect good [<rev>...]
@@ -26,58 +25,71 @@ on the subcommand:
26
25
git bisect replay <logfile>
27
26
git bisect log
28
27
git bisect run <cmd>...
28
+ git bisect help
29
29
30
- This command uses 'git rev-list --bisect' to help drive the
31
- binary search process to find which change introduced a bug, given an
32
- old "good" commit object name and a later "bad" commit object name.
30
+ This command uses a binary search algorithm to find which commit in
31
+ your project's history introduced a bug. You use it by first telling
32
+ it a "bad" commit that is known to contain the bug, and a "good"
33
+ commit that is known to be before the bug was introduced. Then `git
34
+ bisect` picks a commit between those two endpoints and asks you
35
+ whether the selected commit is "good" or "bad". It continues narrowing
36
+ down the range until it finds the exact commit that introduced the
37
+ change.
33
38
34
39
Basic bisect commands: start, bad, good
35
40
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
41
37
- Using the Linux kernel tree as an example, basic use of the bisect
38
- command is as follows:
42
+ As an example, suppose you are trying to find the commit that broke a
43
+ feature that was known to work in version `v2.6.13-rc2` of your
44
+ project. You start a bisect session as follows:
39
45
40
46
------------------------------------------------
41
47
$ git bisect start
42
48
$ git bisect bad # Current version is bad
43
- $ git bisect good v2.6.13-rc2 # v2.6.13-rc2 was the last version
44
- # tested that was good
49
+ $ git bisect good v2.6.13-rc2 # v2.6.13-rc2 is known to be good
50
+ ------------------------------------------------
51
+
52
+ Once you have specified at least one bad and one good commit, `git
53
+ bisect` selects a commit in the middle of that range of history,
54
+ checks it out, and outputs something similar to the following:
55
+
56
+ ------------------------------------------------
57
+ Bisecting: 675 revisions left to test after this (roughly 10 steps)
45
58
------------------------------------------------
46
59
47
- When you have specified at least one bad and one good version, the
48
- command bisects the revision tree and outputs something similar to
49
- the following:
60
+ You should now compile the checked-out version and test it. If that
61
+ version works correctly, type
50
62
51
63
------------------------------------------------
52
- Bisecting: 675 revisions left to test after this
64
+ $ git bisect good
53
65
------------------------------------------------
54
66
55
- The state in the middle of the set of revisions is then checked out.
56
- You would now compile that kernel and boot it. If the booted kernel
57
- works correctly, you would then issue the following command:
67
+ If that version is broken, type
58
68
59
69
------------------------------------------------
60
- $ git bisect good # this one is good
70
+ $ git bisect bad
61
71
------------------------------------------------
62
72
63
- The output of this command would be something similar to the following:
73
+ Then `git bisect` will respond with something like
64
74
65
75
------------------------------------------------
66
- Bisecting: 337 revisions left to test after this
76
+ Bisecting: 337 revisions left to test after this (roughly 9 steps)
67
77
------------------------------------------------
68
78
69
- You keep repeating this process, compiling the tree, testing it, and
70
- depending on whether it is good or bad issuing the command "git bisect good"
71
- or "git bisect bad" to ask for the next bisection.
79
+ Keep repeating the process: compile the tree, test it, and depending
80
+ on whether it is good or bad run `git bisect good` or `git bisect bad`
81
+ to ask for the next commit that needs testing.
82
+
83
+ Eventually there will be no more revisions left to inspect, and the
84
+ command will print out a description of the first bad commit. The
85
+ reference `refs/bisect/bad` will be left pointing at that commit.
72
86
73
- Eventually there will be no more revisions left to bisect, and you
74
- will have been left with the first bad kernel revision in "refs/bisect/bad".
75
87
76
88
Bisect reset
77
89
~~~~~~~~~~~~
78
90
79
91
After a bisect session, to clean up the bisection state and return to
80
- the original HEAD (i.e., to quit bisecting) , issue the following command:
92
+ the original HEAD, issue the following command:
81
93
82
94
------------------------------------------------
83
95
$ git bisect reset
@@ -94,9 +106,10 @@ instead:
94
106
$ git bisect reset <commit>
95
107
------------------------------------------------
96
108
97
- For example, `git bisect reset HEAD` will leave you on the current
98
- bisection commit and avoid switching commits at all, while `git bisect
99
- reset bisect/bad` will check out the first bad revision.
109
+ For example, `git bisect reset bisect/bad` will check out the first
110
+ bad revision, while `git bisect reset HEAD` will leave you on the
111
+ current bisection commit and avoid switching commits at all.
112
+
100
113
101
114
Bisect visualize
102
115
~~~~~~~~~~~~~~~~
@@ -141,17 +154,17 @@ $ git bisect replay that-file
141
154
Avoiding testing a commit
142
155
~~~~~~~~~~~~~~~~~~~~~~~~~
143
156
144
- If, in the middle of a bisect session, you know that the next suggested
145
- revision is not a good one to test (e.g. the change the commit
146
- introduces is known not to work in your environment and you know it
147
- does not have anything to do with the bug you are chasing), you may
148
- want to find a nearby commit and try that instead.
157
+ If, in the middle of a bisect session, you know that the suggested
158
+ revision is not a good one to test (e.g. it fails to build and you
159
+ know that the failure does not have anything to do with the bug you
160
+ are chasing), you can manually select a nearby commit and test that
161
+ one instead.
149
162
150
163
For example:
151
164
152
165
------------
153
166
$ git bisect good/bad # previous round was good or bad.
154
- Bisecting: 337 revisions left to test after this
167
+ Bisecting: 337 revisions left to test after this (roughly 9 steps)
155
168
$ git bisect visualize # oops, that is uninteresting.
156
169
$ git reset --hard HEAD~3 # try 3 revisions before what
157
170
# was suggested
@@ -163,18 +176,19 @@ the revision as good or bad in the usual manner.
163
176
Bisect skip
164
177
~~~~~~~~~~~~
165
178
166
- Instead of choosing by yourself a nearby commit, you can ask Git
167
- to do it for you by issuing the command:
179
+ Instead of choosing a nearby commit by yourself , you can ask Git to do
180
+ it for you by issuing the command:
168
181
169
182
------------
170
183
$ git bisect skip # Current version cannot be tested
171
184
------------
172
185
173
- But Git may eventually be unable to tell the first bad commit among
174
- a bad commit and one or more skipped commits.
186
+ However, if you skip a commit adjacent to the one you are looking for,
187
+ Git will be unable to tell exactly which of those commits was the
188
+ first bad one.
175
189
176
- You can even skip a range of commits, instead of just one commit,
177
- using the "'<commit1>'..'<commit2>'" notation. For example:
190
+ You can also skip a range of commits, instead of just one commit,
191
+ using range notation. For example:
178
192
179
193
------------
180
194
$ git bisect skip v2.5..v2.6
@@ -190,8 +204,8 @@ would issue the command:
190
204
$ git bisect skip v2.5 v2.5..v2.6
191
205
------------
192
206
193
- This tells the bisect process that the commits between `v2.5` included
194
- and `v2.6` included should be skipped.
207
+ This tells the bisect process that the commits between `v2.5` and
208
+ `v2.6` (inclusive) should be skipped.
195
209
196
210
197
211
Cutting down bisection by giving more parameters to bisect start
@@ -225,14 +239,14 @@ or bad, you can bisect by issuing the command:
225
239
$ git bisect run my_script arguments
226
240
------------
227
241
228
- Note that the script (`my_script` in the above example) should
229
- exit with code 0 if the current source code is good, and exit with a
230
- code between 1 and 127 (inclusive), except 125, if the current
231
- source code is bad.
242
+ Note that the script (`my_script` in the above example) should exit
243
+ with code 0 if the current source code is good/old , and exit with a
244
+ code between 1 and 127 (inclusive), except 125, if the current source
245
+ code is bad/new .
232
246
233
247
Any other exit code will abort the bisect process. It should be noted
234
- that a program that terminates via " exit(-1)" leaves $? = 255, (see the
235
- exit(3) manual page), as the value is chopped with " & 0377" .
248
+ that a program that terminates via ` exit(-1)` leaves $? = 255, (see the
249
+ exit(3) manual page), as the value is chopped with ` & 0377` .
236
250
237
251
The special exit code 125 should be used when the current source code
238
252
cannot be tested. If the script exits with this code, the current
@@ -241,7 +255,7 @@ as the highest sensible value to use for this purpose, because 126 and 127
241
255
are used by POSIX shells to signal specific error status (127 is for
242
256
command not found, 126 is for command found but not executable---these
243
257
details do not matter, as they are normal errors in the script, as far as
244
- " bisect run" is concerned).
258
+ ` bisect run` is concerned).
245
259
246
260
You may often find that during a bisect session you want to have
247
261
temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a
@@ -254,7 +268,7 @@ next revision to test, the script can apply the patch
254
268
before compiling, run the real test, and afterwards decide if the
255
269
revision (possibly with the needed patch) passed the test and then
256
270
rewind the tree to the pristine state. Finally the script should exit
257
- with the status of the real test to let the " git bisect run" command loop
271
+ with the status of the real test to let the ` git bisect run` command loop
258
272
determine the eventual outcome of the bisect session.
259
273
260
274
OPTIONS
@@ -301,12 +315,12 @@ $ git bisect run ~/test.sh
301
315
$ git bisect reset # quit the bisect session
302
316
------------
303
317
+
304
- Here we use a " test.sh" custom script. In this script, if " make"
318
+ Here we use a ` test.sh` custom script. In this script, if ` make`
305
319
fails, we skip the current commit.
306
- " check_test_case.sh" should " exit 0" if the test case passes,
307
- and " exit 1" otherwise.
320
+ ` check_test_case.sh` should ` exit 0` if the test case passes,
321
+ and ` exit 1` otherwise.
308
322
+
309
- It is safer if both " test.sh" and " check_test_case.sh" are
323
+ It is safer if both ` test.sh` and ` check_test_case.sh` are
310
324
outside the repository to prevent interactions between the bisect,
311
325
make and test processes and the scripts.
312
326
0 commit comments