]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-bisect.txt
Bisect run: "skip" current commit if script exit code is 125.
[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
6fe9c570 18 git bisect start [<bad> [<good>...]] [--] [<paths>...]
c39ce918
CC
19 git bisect bad [<rev>]
20 git bisect good [<rev>...]
21 git bisect skip [<rev>...]
556cb4e5
JH
22 git bisect reset [<branch>]
23 git bisect visualize
24 git bisect replay <logfile>
25 git bisect log
a17c4101 26 git bisect run <cmd>...
556cb4e5 27
fed820ad
CC
28This command uses 'git-rev-list --bisect' option to help drive the
29binary search process to find which change introduced a bug, given an
30old "good" commit object name and a later "bad" commit object name.
7fc9d69f 31
1207f9e7
CC
32Basic bisect commands: start, bad, good
33~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34
f85a4191 35The way you use it is:
7fc9d69f 36
f85a4191 37------------------------------------------------
556cb4e5 38$ git bisect start
6cea0555
CC
39$ git bisect bad # Current version is bad
40$ git bisect good v2.6.13-rc2 # v2.6.13-rc2 was the last version
41 # tested that was good
f85a4191 42------------------------------------------------
7fc9d69f 43
fed820ad
CC
44When you give at least one bad and one good versions, it will bisect
45the revision tree and say something like:
f85a4191
JH
46
47------------------------------------------------
48Bisecting: 675 revisions left to test after this
49------------------------------------------------
50
fed820ad
CC
51and check out the state in the middle. Now, compile that kernel, and
52boot it. Now, let's say that this booted kernel works fine, then just
53do
f85a4191
JH
54
55------------------------------------------------
556cb4e5 56$ git bisect good # this one is good
f85a4191
JH
57------------------------------------------------
58
59which will now say
60
61------------------------------------------------
62Bisecting: 337 revisions left to test after this
63------------------------------------------------
64
fed820ad
CC
65and you continue along, compiling that one, testing it, and depending
66on whether it is good or bad, you say "git bisect good" or "git bisect
67bad", and ask for the next bisection.
f85a4191 68
fed820ad
CC
69Until you have no more left, and you'll have been left with the first
70bad kernel rev in "refs/bisect/bad".
f85a4191 71
1207f9e7
CC
72Bisect reset
73~~~~~~~~~~~~
74
f85a4191
JH
75Oh, and then after you want to reset to the original head, do a
76
77------------------------------------------------
556cb4e5 78$ git bisect reset
f85a4191
JH
79------------------------------------------------
80
fed820ad
CC
81to get back to the master branch, instead of being in one of the
82bisection branches ("git bisect start" will do that for you too,
83actually: it will reset the bisection state, and before it does that
84it checks that you're not using some old bisection branch).
7fc9d69f 85
1207f9e7
CC
86Bisect visualize
87~~~~~~~~~~~~~~~~
88
8db9307c
JH
89During the bisection process, you can say
90
556cb4e5
JH
91------------
92$ git bisect visualize
93------------
8db9307c
JH
94
95to see the currently remaining suspects in `gitk`.
96
1207f9e7
CC
97Bisect log and bisect replay
98~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99
fed820ad
CC
100The good/bad input is logged, and
101
102------------
103$ git bisect log
104------------
105
106shows what you have done so far. You can truncate its output somewhere
107and save it in a file, and run
b595ed14 108
556cb4e5
JH
109------------
110$ git bisect replay that-file
111------------
b595ed14
JH
112
113if you find later you made a mistake telling good/bad about a
114revision.
115
1207f9e7
CC
116Avoiding to test a commit
117~~~~~~~~~~~~~~~~~~~~~~~~~
118
fed820ad
CC
119If in a middle of bisect session, you know what the bisect suggested
120to try next is not a good one to test (e.g. the change the commit
121introduces is known not to work in your environment and you know it
122does not have anything to do with the bug you are chasing), you may
123want to find a near-by commit and try that instead.
124
125It goes something like this:
556cb4e5
JH
126
127------------
128$ git bisect good/bad # previous round was good/bad.
129Bisecting: 337 revisions left to test after this
130$ git bisect visualize # oops, that is uninteresting.
131$ git reset --hard HEAD~3 # try 3 revs before what
132 # was suggested
133------------
134
fed820ad
CC
135Then compile and test the one you chose to try. After that, tell
136bisect what the result was as usual.
556cb4e5 137
c39ce918
CC
138Bisect skip
139~~~~~~~~~~~~
140
141Instead of choosing by yourself a nearby commit, you may just want git
142to do it for you using:
143
144------------
145$ git bisect skip # Current version cannot be tested
146------------
147
148But computing the commit to test may be slower afterwards and git may
149eventually not be able to tell the first bad among a bad and one or
150more "skip"ped commits.
151
6fe9c570
CC
152Cutting down bisection by giving more parameters to bisect start
153~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1207f9e7 154
fed820ad
CC
155You can further cut down the number of trials if you know what part of
156the tree is involved in the problem you are tracking down, by giving
157paths parameters when you say `bisect start`, like this:
556cb4e5
JH
158
159------------
6fe9c570
CC
160$ git bisect start -- arch/i386 include/asm-i386
161------------
162
163If you know beforehand more than one good commits, you can narrow the
164bisect space down without doing the whole tree checkout every time you
165give good commits. You give the bad revision immediately after `start`
166and then you give all the good revisions you have:
167
168------------
169$ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --
170 # v2.6.20-rc6 is bad
171 # v2.6.20-rc4 and v2.6.20-rc1 are good
556cb4e5
JH
172------------
173
1207f9e7
CC
174Bisect run
175~~~~~~~~~~
176
7891a281
CC
177If you have a script that can tell if the current source code is good
178or bad, you can automatically bisect using:
a17c4101
CC
179
180------------
181$ git bisect run my_script
182------------
183
7891a281 184Note that the "run" script (`my_script` in the above example) should
71b0251c
CC
185exit with code 0 in case the current source code is good. Exit with a
186code between 1 and 127 (inclusive), except 125, if the current
187source code is bad.
a17c4101 188
cc070d1f
CC
189Any other exit code will abort the automatic bisect process. (A
190program that does "exit(-1)" leaves $? = 255, see exit(3) manual page,
191the value is chopped with "& 0377".)
a17c4101 192
71b0251c
CC
193The special exit code 125 should be used when the current source code
194cannot be tested. If the "run" script exits with this code, the current
195revision will be skipped, see `git bisect skip` above.
196
a17c4101
CC
197You may often find that during bisect you want to have near-constant
198tweaks (e.g., s/#define DEBUG 0/#define DEBUG 1/ in a header file, or
199"revision that does not have this commit needs this patch applied to
200work around other problem this bisection is not interested in")
201applied to the revision being tested.
202
203To cope with such a situation, after the inner git-bisect finds the
204next revision to test, with the "run" script, you can apply that tweak
205before compiling, run the real test, and after the test decides if the
206revision (possibly with the needed tweaks) passed the test, rewind the
207tree to the pristine state. Finally the "run" script can exit with
208the status of the real test to let "git bisect run" command loop to
209know the outcome.
7fc9d69f
JH
210
211Author
212------
213Written by Linus Torvalds <torvalds@osdl.org>
214
215Documentation
df8baa42 216-------------
7fc9d69f
JH
217Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
218
219GIT
220---
a7154e91 221Part of the gitlink:git[7] suite