]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-bisect.txt
Documentation: be consistent about "git-" versus "git "
[thirdparty/git.git] / Documentation / git-bisect.txt
CommitLineData
215a7ad1
JH
1git-bisect(1)
2=============
7fc9d69f
JH
3
4NAME
5----
c3f0baac 6git-bisect - Find the change that introduced a bug by binary search
7fc9d69f
JH
7
8
9SYNOPSIS
10--------
a6080a0a 11'git bisect' <subcommand> <options>
7fc9d69f
JH
12
13DESCRIPTION
14-----------
fed820ad
CC
15The command takes various subcommands, and different options depending
16on the subcommand:
556cb4e5 17
243a60fb 18 git bisect help
6fe9c570 19 git bisect start [<bad> [<good>...]] [--] [<paths>...]
c39ce918
CC
20 git bisect bad [<rev>]
21 git bisect good [<rev>...]
22 git bisect skip [<rev>...]
556cb4e5
JH
23 git bisect reset [<branch>]
24 git bisect visualize
25 git bisect replay <logfile>
26 git bisect log
a17c4101 27 git bisect run <cmd>...
556cb4e5 28
b1889c36 29This command uses 'git rev-list --bisect' option to help drive the
fed820ad
CC
30binary search process to find which change introduced a bug, given an
31old "good" commit object name and a later "bad" commit object name.
7fc9d69f 32
243a60fb
CC
33Getting help
34~~~~~~~~~~~~
35
36Use "git bisect" to get a short usage description, and "git bisect
37help" or "git bisect -h" to get a long usage description.
38
1207f9e7
CC
39Basic bisect commands: start, bad, good
40~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41
f85a4191 42The way you use it is:
7fc9d69f 43
f85a4191 44------------------------------------------------
556cb4e5 45$ git bisect start
6cea0555
CC
46$ git bisect bad # Current version is bad
47$ git bisect good v2.6.13-rc2 # v2.6.13-rc2 was the last version
48 # tested that was good
f85a4191 49------------------------------------------------
7fc9d69f 50
fed820ad
CC
51When you give at least one bad and one good versions, it will bisect
52the revision tree and say something like:
f85a4191
JH
53
54------------------------------------------------
55Bisecting: 675 revisions left to test after this
56------------------------------------------------
57
fed820ad
CC
58and check out the state in the middle. Now, compile that kernel, and
59boot it. Now, let's say that this booted kernel works fine, then just
60do
f85a4191
JH
61
62------------------------------------------------
556cb4e5 63$ git bisect good # this one is good
f85a4191
JH
64------------------------------------------------
65
66which will now say
67
68------------------------------------------------
69Bisecting: 337 revisions left to test after this
70------------------------------------------------
71
fed820ad
CC
72and you continue along, compiling that one, testing it, and depending
73on whether it is good or bad, you say "git bisect good" or "git bisect
74bad", and ask for the next bisection.
f85a4191 75
fed820ad
CC
76Until you have no more left, and you'll have been left with the first
77bad kernel rev in "refs/bisect/bad".
f85a4191 78
1207f9e7
CC
79Bisect reset
80~~~~~~~~~~~~
81
f85a4191
JH
82Oh, and then after you want to reset to the original head, do a
83
84------------------------------------------------
556cb4e5 85$ git bisect reset
f85a4191
JH
86------------------------------------------------
87
65e73dba
CC
88to get back to the original branch, instead of being on the bisection
89commit ("git bisect start" will do that for you too, actually: it will
90reset the bisection state).
7fc9d69f 91
1207f9e7
CC
92Bisect visualize
93~~~~~~~~~~~~~~~~
94
8db9307c
JH
95During the bisection process, you can say
96
556cb4e5
JH
97------------
98$ git bisect visualize
99------------
8db9307c 100
235997c9
JH
101to see the currently remaining suspects in `gitk`. `visualize` is a bit
102too long to type and `view` is provided as a synonym.
103
104If `DISPLAY` environment variable is not set, `git log` is used
105instead. You can even give command line options such as `-p` and
106`--stat`.
107
108------------
109$ git bisect view --stat
110------------
8db9307c 111
1207f9e7
CC
112Bisect log and bisect replay
113~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114
fed820ad
CC
115The good/bad input is logged, and
116
117------------
118$ git bisect log
119------------
120
121shows what you have done so far. You can truncate its output somewhere
122and save it in a file, and run
b595ed14 123
556cb4e5
JH
124------------
125$ git bisect replay that-file
126------------
b595ed14
JH
127
128if you find later you made a mistake telling good/bad about a
129revision.
130
1207f9e7
CC
131Avoiding to test a commit
132~~~~~~~~~~~~~~~~~~~~~~~~~
133
fed820ad
CC
134If in a middle of bisect session, you know what the bisect suggested
135to try next is not a good one to test (e.g. the change the commit
136introduces is known not to work in your environment and you know it
137does not have anything to do with the bug you are chasing), you may
138want to find a near-by commit and try that instead.
139
140It goes something like this:
556cb4e5
JH
141
142------------
143$ git bisect good/bad # previous round was good/bad.
144Bisecting: 337 revisions left to test after this
145$ git bisect visualize # oops, that is uninteresting.
146$ git reset --hard HEAD~3 # try 3 revs before what
147 # was suggested
148------------
149
fed820ad
CC
150Then compile and test the one you chose to try. After that, tell
151bisect what the result was as usual.
556cb4e5 152
c39ce918
CC
153Bisect skip
154~~~~~~~~~~~~
155
156Instead of choosing by yourself a nearby commit, you may just want git
157to do it for you using:
158
159------------
160$ git bisect skip # Current version cannot be tested
161------------
162
163But computing the commit to test may be slower afterwards and git may
164eventually not be able to tell the first bad among a bad and one or
165more "skip"ped commits.
166
6fe9c570
CC
167Cutting down bisection by giving more parameters to bisect start
168~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1207f9e7 169
fed820ad
CC
170You can further cut down the number of trials if you know what part of
171the tree is involved in the problem you are tracking down, by giving
172paths parameters when you say `bisect start`, like this:
556cb4e5
JH
173
174------------
6fe9c570
CC
175$ git bisect start -- arch/i386 include/asm-i386
176------------
177
178If you know beforehand more than one good commits, you can narrow the
179bisect space down without doing the whole tree checkout every time you
180give good commits. You give the bad revision immediately after `start`
181and then you give all the good revisions you have:
182
183------------
184$ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --
185 # v2.6.20-rc6 is bad
186 # v2.6.20-rc4 and v2.6.20-rc1 are good
556cb4e5
JH
187------------
188
1207f9e7
CC
189Bisect run
190~~~~~~~~~~
191
7891a281
CC
192If you have a script that can tell if the current source code is good
193or bad, you can automatically bisect using:
a17c4101
CC
194
195------------
196$ git bisect run my_script
197------------
198
7891a281 199Note that the "run" script (`my_script` in the above example) should
71b0251c
CC
200exit with code 0 in case the current source code is good. Exit with a
201code between 1 and 127 (inclusive), except 125, if the current
202source code is bad.
a17c4101 203
cc070d1f
CC
204Any other exit code will abort the automatic bisect process. (A
205program that does "exit(-1)" leaves $? = 255, see exit(3) manual page,
206the value is chopped with "& 0377".)
a17c4101 207
71b0251c
CC
208The special exit code 125 should be used when the current source code
209cannot be tested. If the "run" script exits with this code, the current
210revision will be skipped, see `git bisect skip` above.
211
a17c4101
CC
212You may often find that during bisect you want to have near-constant
213tweaks (e.g., s/#define DEBUG 0/#define DEBUG 1/ in a header file, or
214"revision that does not have this commit needs this patch applied to
215work around other problem this bisection is not interested in")
216applied to the revision being tested.
217
218To cope with such a situation, after the inner git-bisect finds the
219next revision to test, with the "run" script, you can apply that tweak
220before compiling, run the real test, and after the test decides if the
221revision (possibly with the needed tweaks) passed the test, rewind the
222tree to the pristine state. Finally the "run" script can exit with
223the status of the real test to let "git bisect run" command loop to
224know the outcome.
7fc9d69f 225
bac59f19
CC
226EXAMPLES
227--------
228
229* Automatically bisect a broken build between v1.2 and HEAD:
230+
231------------
232$ git bisect start HEAD v1.2 -- # HEAD is bad, v1.2 is good
233$ git bisect run make # "make" builds the app
234------------
235
236* Automatically bisect a broken test suite:
237+
238------------
239$ cat ~/test.sh
240#!/bin/sh
241make || exit 125 # this "skip"s broken builds
242make test # "make test" runs the test suite
243$ git bisect start v1.3 v1.1 -- # v1.3 is bad, v1.1 is good
244$ git bisect run ~/test.sh
245------------
246+
247Here we use a "test.sh" custom script. In this script, if "make"
248fails, we "skip" the current commit.
249+
250It's safer to use a custom script outside the repo to prevent
251interactions between the bisect, make and test processes and the
252script.
253+
254And "make test" should "exit 0", if the test suite passes, and
255"exit 1" (for example) otherwise.
256
257* Automatically bisect a broken test case:
258+
259------------
260$ cat ~/test.sh
261#!/bin/sh
262make || exit 125 # this "skip"s broken builds
263~/check_test_case.sh # does the test case passes ?
264$ git bisect start HEAD HEAD~10 -- # culprit is among the last 10
265$ git bisect run ~/test.sh
266------------
267+
268Here "check_test_case.sh" should "exit 0", if the test case passes,
269and "exit 1" (for example) otherwise.
270+
271It's safer if both "test.sh" and "check_test_case.sh" scripts are
272outside the repo to prevent interactions between the bisect, make and
273test processes and the scripts.
274
7fc9d69f
JH
275Author
276------
277Written by Linus Torvalds <torvalds@osdl.org>
278
279Documentation
df8baa42 280-------------
7fc9d69f
JH
281Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
282
283GIT
284---
9e1f0a85 285Part of the linkgit:git[1] suite