Skip to content

Commit 71cc600

Browse files
committed
Merge branch 'ad/bisect-cleanup'
Code and documentation clean-up to "git bisect". * ad/bisect-cleanup: bisect: don't mix option parsing and non-trivial code bisect: simplify the addition of new bisect terms bisect: replace hardcoded "bad|good" by variables Documentation/bisect: revise overall content Documentation/bisect: move getting help section to the end bisect: correction of typo
2 parents efc8a62 + 4a6ada3 commit 71cc600

File tree

6 files changed

+266
-116
lines changed

6 files changed

+266
-116
lines changed

Documentation/git-bisect.txt

Lines changed: 73 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ git-bisect(1)
33

44
NAME
55
----
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
77

88

99
SYNOPSIS
@@ -16,7 +16,6 @@ DESCRIPTION
1616
The command takes various subcommands, and different options depending
1717
on the subcommand:
1818

19-
git bisect help
2019
git bisect start [--no-checkout] [<bad> [<good>...]] [--] [<paths>...]
2120
git bisect bad [<rev>]
2221
git bisect good [<rev>...]
@@ -26,64 +25,71 @@ on the subcommand:
2625
git bisect replay <logfile>
2726
git bisect log
2827
git bisect run <cmd>...
28+
git bisect help
2929

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.
33-
34-
Getting help
35-
~~~~~~~~~~~~
36-
37-
Use "git bisect" to get a short usage description, and "git bisect
38-
help" or "git bisect -h" to get a long usage description.
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.
3938

4039
Basic bisect commands: start, bad, good
4140
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4241

43-
Using the Linux kernel tree as an example, basic use of the bisect
44-
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:
4545

4646
------------------------------------------------
4747
$ git bisect start
4848
$ git bisect bad # Current version is bad
49-
$ git bisect good v2.6.13-rc2 # v2.6.13-rc2 was the last version
50-
# tested that was good
49+
$ git bisect good v2.6.13-rc2 # v2.6.13-rc2 is known to be good
5150
------------------------------------------------
5251

53-
When you have specified at least one bad and one good version, the
54-
command bisects the revision tree and outputs something similar to
55-
the following:
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:
5655

5756
------------------------------------------------
58-
Bisecting: 675 revisions left to test after this
57+
Bisecting: 675 revisions left to test after this (roughly 10 steps)
5958
------------------------------------------------
6059

61-
The state in the middle of the set of revisions is then checked out.
62-
You would now compile that kernel and boot it. If the booted kernel
63-
works correctly, you would then issue the following command:
60+
You should now compile the checked-out version and test it. If that
61+
version works correctly, type
6462

6563
------------------------------------------------
66-
$ git bisect good # this one is good
64+
$ git bisect good
6765
------------------------------------------------
6866

69-
The output of this command would be something similar to the following:
67+
If that version is broken, type
7068

7169
------------------------------------------------
72-
Bisecting: 337 revisions left to test after this
70+
$ git bisect bad
7371
------------------------------------------------
7472

75-
You keep repeating this process, compiling the tree, testing it, and
76-
depending on whether it is good or bad issuing the command "git bisect good"
77-
or "git bisect bad" to ask for the next bisection.
73+
Then `git bisect` will respond with something like
74+
75+
------------------------------------------------
76+
Bisecting: 337 revisions left to test after this (roughly 9 steps)
77+
------------------------------------------------
78+
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.
7886

79-
Eventually there will be no more revisions left to bisect, and you
80-
will have been left with the first bad kernel revision in "refs/bisect/bad".
8187

8288
Bisect reset
8389
~~~~~~~~~~~~
8490

8591
After a bisect session, to clean up the bisection state and return to
86-
the original HEAD (i.e., to quit bisecting), issue the following command:
92+
the original HEAD, issue the following command:
8793

8894
------------------------------------------------
8995
$ git bisect reset
@@ -100,9 +106,10 @@ instead:
100106
$ git bisect reset <commit>
101107
------------------------------------------------
102108

103-
For example, `git bisect reset HEAD` will leave you on the current
104-
bisection commit and avoid switching commits at all, while `git bisect
105-
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+
106113

107114
Bisect visualize
108115
~~~~~~~~~~~~~~~~
@@ -147,17 +154,17 @@ $ git bisect replay that-file
147154
Avoiding testing a commit
148155
~~~~~~~~~~~~~~~~~~~~~~~~~
149156

150-
If, in the middle of a bisect session, you know that the next suggested
151-
revision is not a good one to test (e.g. the change the commit
152-
introduces is known not to work in your environment and you know it
153-
does not have anything to do with the bug you are chasing), you may
154-
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.
155162

156163
For example:
157164

158165
------------
159166
$ git bisect good/bad # previous round was good or bad.
160-
Bisecting: 337 revisions left to test after this
167+
Bisecting: 337 revisions left to test after this (roughly 9 steps)
161168
$ git bisect visualize # oops, that is uninteresting.
162169
$ git reset --hard HEAD~3 # try 3 revisions before what
163170
# was suggested
@@ -169,18 +176,19 @@ the revision as good or bad in the usual manner.
169176
Bisect skip
170177
~~~~~~~~~~~~
171178

172-
Instead of choosing by yourself a nearby commit, you can ask Git
173-
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:
174181

175182
------------
176183
$ git bisect skip # Current version cannot be tested
177184
------------
178185

179-
But Git may eventually be unable to tell the first bad commit among
180-
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.
181189

182-
You can even skip a range of commits, instead of just one commit,
183-
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:
184192

185193
------------
186194
$ git bisect skip v2.5..v2.6
@@ -196,8 +204,8 @@ would issue the command:
196204
$ git bisect skip v2.5 v2.5..v2.6
197205
------------
198206

199-
This tells the bisect process that the commits between `v2.5` included
200-
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.
201209

202210

203211
Cutting down bisection by giving more parameters to bisect start
@@ -231,14 +239,14 @@ or bad, you can bisect by issuing the command:
231239
$ git bisect run my_script arguments
232240
------------
233241

234-
Note that the script (`my_script` in the above example) should
235-
exit with code 0 if the current source code is good, and exit with a
236-
code between 1 and 127 (inclusive), except 125, if the current
237-
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.
238246

239247
Any other exit code will abort the bisect process. It should be noted
240-
that a program that terminates via "exit(-1)" leaves $? = 255, (see the
241-
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`.
242250

243251
The special exit code 125 should be used when the current source code
244252
cannot be tested. If the script exits with this code, the current
@@ -247,7 +255,7 @@ as the highest sensible value to use for this purpose, because 126 and 127
247255
are used by POSIX shells to signal specific error status (127 is for
248256
command not found, 126 is for command found but not executable---these
249257
details do not matter, as they are normal errors in the script, as far as
250-
"bisect run" is concerned).
258+
`bisect run` is concerned).
251259

252260
You may often find that during a bisect session you want to have
253261
temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a
@@ -260,7 +268,7 @@ next revision to test, the script can apply the patch
260268
before compiling, run the real test, and afterwards decide if the
261269
revision (possibly with the needed patch) passed the test and then
262270
rewind the tree to the pristine state. Finally the script should exit
263-
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
264272
determine the eventual outcome of the bisect session.
265273

266274
OPTIONS
@@ -307,12 +315,12 @@ $ git bisect run ~/test.sh
307315
$ git bisect reset # quit the bisect session
308316
------------
309317
+
310-
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`
311319
fails, we skip the current commit.
312-
"check_test_case.sh" should "exit 0" if the test case passes,
313-
and "exit 1" otherwise.
320+
`check_test_case.sh` should `exit 0` if the test case passes,
321+
and `exit 1` otherwise.
314322
+
315-
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
316324
outside the repository to prevent interactions between the bisect,
317325
make and test processes and the scripts.
318326

@@ -379,6 +387,11 @@ In this case, when 'git bisect run' finishes, bisect/bad will refer to a commit
379387
has at least one parent whose reachable graph is fully traversable in the sense
380388
required by 'git pack objects'.
381389

390+
Getting help
391+
~~~~~~~~~~~~
392+
393+
Use `git bisect` to get a short usage description, and `git bisect
394+
help` or `git bisect -h` to get a long usage description.
382395

383396
SEE ALSO
384397
--------

0 commit comments

Comments
 (0)