Documentation: reword example text in git-bisect.txt.
[git/dscho.git] / Documentation / git-bisect.txt
blobec9594eda37b339119b5a24c23db22e4789c898e
1 git-bisect(1)
2 =============
4 NAME
5 ----
6 git-bisect - Find by binary search the change that introduced a bug
9 SYNOPSIS
10 --------
11 'git bisect' <subcommand> <options>
13 DESCRIPTION
14 -----------
15 The command takes various subcommands, and different options depending
16 on the subcommand:
18  git bisect help
19  git bisect start [<bad> [<good>...]] [--] [<paths>...]
20  git bisect bad [<rev>]
21  git bisect good [<rev>...]
22  git bisect skip [(<rev>|<range>)...]
23  git bisect reset [<branch>]
24  git bisect visualize
25  git bisect replay <logfile>
26  git bisect log
27  git bisect run <cmd>...
29 This command uses 'git rev-list --bisect' to help drive the
30 binary search process to find which change introduced a bug, given an
31 old "good" commit object name and a later "bad" commit object name.
33 Getting help
34 ~~~~~~~~~~~~
36 Use "git bisect" to get a short usage description, and "git bisect
37 help" or "git bisect -h" to get a long usage description.
39 Basic bisect commands: start, bad, good
40 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42 Using the Linux kernel tree as an example, basic use of the bisect
43 command is as follows:
45 ------------------------------------------------
46 $ git bisect start
47 $ git bisect bad                 # Current version is bad
48 $ git bisect good v2.6.13-rc2    # v2.6.13-rc2 was the last version
49                                  # tested that was good
50 ------------------------------------------------
52 When you have specified at least one bad and one good version, the
53 command bisects the revision tree and outputs something similar to
54 the following:
56 ------------------------------------------------
57 Bisecting: 675 revisions left to test after this
58 ------------------------------------------------
60 The state in the middle of the set of revisions is then checked out.
61 You would now compile that kernel and boot it. If the booted kernel
62 works correctly, you would then issue the following command:
64 ------------------------------------------------
65 $ git bisect good                       # this one is good
66 ------------------------------------------------
68 The output of this command would be something similar to the following:
70 ------------------------------------------------
71 Bisecting: 337 revisions left to test after this
72 ------------------------------------------------
74 You keep repeating this process, compiling the tree, testing it, and
75 depending on whether it is good or bad issuing the command "git bisect good"
76 or "git bisect bad" to ask for the next bisection.
78 Eventually there will be no more revisions left to bisect, and you
79 will have been left with the first bad kernel revision in "refs/bisect/bad".
81 Bisect reset
82 ~~~~~~~~~~~~
84 To return to the original head after a bisect session, you issue the
85 following command:
87 ------------------------------------------------
88 $ git bisect reset
89 ------------------------------------------------
91 This resets the tree to the original branch instead of being on the
92 bisection commit ("git bisect start" will also do that, as it resets
93 the bisection state).
95 Bisect visualize
96 ~~~~~~~~~~~~~~~~
98 To see the currently remaining suspects in 'gitk', the following command
99 is issued during the bisection process:
101 ------------
102 $ git bisect visualize
103 ------------
105 `view` may also be used as a synonym for `visualize`.
107 If the 'DISPLAY' environment variable is not set, 'git log' is used
108 instead.  You can also give command line options such as `-p` and
109 `--stat`.
111 ------------
112 $ git bisect view --stat
113 ------------
115 Bisect log and bisect replay
116 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118 After having marked revisions as good or bad, you issue the following
119 command to show what has been done so far:
121 ------------
122 $ git bisect log
123 ------------
125 If you discover that you made a mistake in specifying the status of a
126 revision, you can save the output of this command to a file, edit it to
127 remove the incorrect entries, and then issue the following commands to
128 return to a corrected state:
130 ------------
131 $ git bisect reset
132 $ git bisect replay that-file
133 ------------
135 Avoiding testing a commit
136 ~~~~~~~~~~~~~~~~~~~~~~~~~
138 If in the middle of a bisect session, you know that the next suggested
139 revision is not a good one to test (e.g. the change the commit
140 introduces is known not to work in your environment and you know it
141 does not have anything to do with the bug you are chasing), you may
142 want to find a nearby commit and try that instead.
144 For example:
146 ------------
147 $ git bisect good/bad                   # previous round was good or bad.
148 Bisecting: 337 revisions left to test after this
149 $ git bisect visualize                  # oops, that is uninteresting.
150 $ git reset --hard HEAD~3               # try 3 revisions before what
151                                         # was suggested
152 ------------
154 Then compile and test the chosen revision. Afterwards the revision
155 is marked as good or bad in the usual manner.
157 Bisect skip
158 ~~~~~~~~~~~~
160 Instead of choosing by yourself a nearby commit, you can ask git
161 to do it for you by issuing the command:
163 ------------
164 $ git bisect skip                 # Current version cannot be tested
165 ------------
167 But computing the commit to test may be slower afterwards and git may
168 eventually not be able to tell the first bad commit among a bad commit
169 and one or more skipped commits.
171 You can even skip a range of commits, instead of just one commit,
172 using the "'<commit1>'..'<commit2>'" notation. For example:
174 ------------
175 $ git bisect skip v2.5..v2.6
176 ------------
178 The effect of this would be that no commit between `v2.5` excluded and
179 `v2.6` included could be tested.
181 Note that if you also want to skip the first commit of the range you
182 would issue the command:
184 ------------
185 $ git bisect skip v2.5 v2.5..v2.6
186 ------------
188 This would cause the commits between `v2.5` included and `v2.6` included
189 to be skipped.
192 Cutting down bisection by giving more parameters to bisect start
193 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195 You can further cut down the number of trials, if you know what part of
196 the tree is involved in the problem you are tracking down, by specifying
197 path parameters when issuing the `bisect start` command:
199 ------------
200 $ git bisect start -- arch/i386 include/asm-i386
201 ------------
203 If you know beforehand more than one good commit, you can narrow the
204 bisect space down by specifying all of the good commits immediately after
205 the bad commit when issuing the `bisect start` command:
207 ------------
208 $ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --
209                    # v2.6.20-rc6 is bad
210                    # v2.6.20-rc4 and v2.6.20-rc1 are good
211 ------------
213 Bisect run
214 ~~~~~~~~~~
216 If you have a script that can tell if the current source code is good
217 or bad, you can bisect by issuing the command:
219 ------------
220 $ git bisect run my_script
221 ------------
223 Note that the script (`my_script` in the above example) should
224 exit with code 0 if the current source code is good, and exit with a
225 code between 1 and 127 (inclusive), except 125, if the current
226 source code is bad.
228 Any other exit code will abort the bisect process. It should be noted
229 that a program that terminates via "exit(-1)" leaves $? = 255, (see the
230 exit(3) manual page), as the value is chopped with "& 0377".
232 The special exit code 125 should be used when the current source code
233 cannot be tested. If the script exits with this code, the current
234 revision will be skipped (see `git bisect skip` above).
236 You may often find that during a bisect session you want to have
237 temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a
238 header file, or "revision that does not have this commit needs this
239 patch applied to work around another problem this bisection is not
240 interested in") applied to the revision being tested.
242 To cope with such a situation, after the inner 'git bisect' finds the
243 next revision to test, the script can apply the patch
244 before compiling, run the real test, and afterwards decide if the
245 revision (possibly with the needed patch) passed the test and then
246 rewind the tree to the pristine state.  Finally the script should exit
247 with the status of the real test to let the "git bisect run" command loop
248 determine the eventual outcome of the bisect session.
250 EXAMPLES
251 --------
253 * Automatically bisect a broken build between v1.2 and HEAD:
255 ------------
256 $ git bisect start HEAD v1.2 --      # HEAD is bad, v1.2 is good
257 $ git bisect run make                # "make" builds the app
258 ------------
260 * Automatically bisect a broken test suite:
262 ------------
263 $ cat ~/test.sh
264 #!/bin/sh
265 make || exit 125                   # this skips broken builds
266 make test                          # "make test" runs the test suite
267 $ git bisect start v1.3 v1.1 --    # v1.3 is bad, v1.1 is good
268 $ git bisect run ~/test.sh
269 ------------
271 Here we use a "test.sh" custom script. In this script, if "make"
272 fails, we skip the current commit.
274 It is safer to use a custom script outside the repository to prevent
275 interactions between the bisect, make and test processes and the
276 script.
278 "make test" should "exit 0", if the test suite passes, and
279 "exit 1" otherwise.
281 * Automatically bisect a broken test case:
283 ------------
284 $ cat ~/test.sh
285 #!/bin/sh
286 make || exit 125                     # this skips broken builds
287 ~/check_test_case.sh                 # does the test case passes ?
288 $ git bisect start HEAD HEAD~10 --   # culprit is among the last 10
289 $ git bisect run ~/test.sh
290 ------------
292 Here "check_test_case.sh" should "exit 0" if the test case passes,
293 and "exit 1" otherwise.
295 It is safer if both "test.sh" and "check_test_case.sh" scripts are
296 outside the repository to prevent interactions between the bisect,
297 make and test processes and the scripts.
299 Author
300 ------
301 Written by Linus Torvalds <torvalds@osdl.org>
303 Documentation
304 -------------
305 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
309 Part of the linkgit:git[1] suite