Skip to content

Commit 2df5a84

Browse files
mhaggergitster
authored andcommitted
Documentation/bisect: revise overall content
Thoroughly revise the "git bisect" manpage, including: * Beef up the "Description" section. * Make the first long example less specific to kernel development. * De-emphasize implementation details in a couple of places. * Add "(roughly N steps)" in the places where example output is shown. * Properly markup code within the prose. * Lots of wordsmithing. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c949397 commit 2df5a84

File tree

1 file changed

+68
-54
lines changed

1 file changed

+68
-54
lines changed

Documentation/git-bisect.txt

Lines changed: 68 additions & 54 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,58 +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.
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.
3338

3439
Basic bisect commands: start, bad, good
3540
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3641

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:
3945

4046
------------------------------------------------
4147
$ git bisect start
4248
$ 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)
4558
------------------------------------------------
4659

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
5062

5163
------------------------------------------------
52-
Bisecting: 675 revisions left to test after this
64+
$ git bisect good
5365
------------------------------------------------
5466

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
5868

5969
------------------------------------------------
60-
$ git bisect good # this one is good
70+
$ git bisect bad
6171
------------------------------------------------
6272

63-
The output of this command would be something similar to the following:
73+
Then `git bisect` will respond with something like
6474

6575
------------------------------------------------
66-
Bisecting: 337 revisions left to test after this
76+
Bisecting: 337 revisions left to test after this (roughly 9 steps)
6777
------------------------------------------------
6878

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.
7286

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".
7587

7688
Bisect reset
7789
~~~~~~~~~~~~
7890

7991
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:
8193

8294
------------------------------------------------
8395
$ git bisect reset
@@ -94,9 +106,10 @@ instead:
94106
$ git bisect reset <commit>
95107
------------------------------------------------
96108

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+
100113

101114
Bisect visualize
102115
~~~~~~~~~~~~~~~~
@@ -141,17 +154,17 @@ $ git bisect replay that-file
141154
Avoiding testing a commit
142155
~~~~~~~~~~~~~~~~~~~~~~~~~
143156

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.
149162

150163
For example:
151164

152165
------------
153166
$ 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)
155168
$ git bisect visualize # oops, that is uninteresting.
156169
$ git reset --hard HEAD~3 # try 3 revisions before what
157170
# was suggested
@@ -163,18 +176,19 @@ the revision as good or bad in the usual manner.
163176
Bisect skip
164177
~~~~~~~~~~~~
165178

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:
168181

169182
------------
170183
$ git bisect skip # Current version cannot be tested
171184
------------
172185

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.
175189

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:
178192

179193
------------
180194
$ git bisect skip v2.5..v2.6
@@ -190,8 +204,8 @@ would issue the command:
190204
$ git bisect skip v2.5 v2.5..v2.6
191205
------------
192206

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.
195209

196210

197211
Cutting down bisection by giving more parameters to bisect start
@@ -225,14 +239,14 @@ or bad, you can bisect by issuing the command:
225239
$ git bisect run my_script arguments
226240
------------
227241

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.
232246

233247
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`.
236250

237251
The special exit code 125 should be used when the current source code
238252
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
241255
are used by POSIX shells to signal specific error status (127 is for
242256
command not found, 126 is for command found but not executable---these
243257
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).
245259

246260
You may often find that during a bisect session you want to have
247261
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
254268
before compiling, run the real test, and afterwards decide if the
255269
revision (possibly with the needed patch) passed the test and then
256270
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
258272
determine the eventual outcome of the bisect session.
259273

260274
OPTIONS
@@ -301,12 +315,12 @@ $ git bisect run ~/test.sh
301315
$ git bisect reset # quit the bisect session
302316
------------
303317
+
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`
305319
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.
308322
+
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
310324
outside the repository to prevent interactions between the bisect,
311325
make and test processes and the scripts.
312326

0 commit comments

Comments
 (0)