make some more strings translatable
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-bisect.html.xml
blobcec079a5bdaaf43aade447bb41af8455b7c171b3
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">\r
3 \r
4 <article lang="en" id="git-bisect(1)">\r
5 <articleinfo>\r
6     <title>git-bisect(1)</title>\r
7         <indexterm>\r
8                 <primary>git-bisect(1)</primary>\r
9         </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-bisect - Find the change that introduced a bug by binary search</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <simpara><emphasis>git bisect</emphasis> &lt;subcommand&gt; &lt;options&gt;</simpara>\r
18 </simplesect>\r
19 <simplesect id="_description">\r
20 <title>DESCRIPTION</title>\r
21 <simpara>The command takes various subcommands, and different options depending\r
22 on the subcommand:</simpara>\r
23 <literallayout class="monospaced">git bisect help\r
24 git bisect start [&lt;bad&gt; [&lt;good&gt;...]] [--] [&lt;paths&gt;...]\r
25 git bisect bad [&lt;rev&gt;]\r
26 git bisect good [&lt;rev&gt;...]\r
27 git bisect skip [(&lt;rev&gt;|&lt;range&gt;)...]\r
28 git bisect reset [&lt;branch&gt;]\r
29 git bisect visualize\r
30 git bisect replay &lt;logfile&gt;\r
31 git bisect log\r
32 git bisect run &lt;cmd&gt;...</literallayout>\r
33 <simpara>This command uses <emphasis>git rev-list --bisect</emphasis> to help drive the\r
34 binary search process to find which change introduced a bug, given an\r
35 old "good" commit object name and a later "bad" commit object name.</simpara>\r
36 <simplesect id="_getting_help">\r
37 <title>Getting help</title>\r
38 <simpara>Use "git bisect" to get a short usage description, and "git bisect\r
39 help" or "git bisect -h" to get a long usage description.</simpara>\r
40 </simplesect>\r
41 <simplesect id="_basic_bisect_commands_start_bad_good">\r
42 <title>Basic bisect commands: start, bad, good</title>\r
43 <simpara>The way you use it is:</simpara>\r
44 <literallayout>$ git bisect start\r
45 $ git bisect bad                 # Current version is bad\r
46 $ git bisect good v2.6.13-rc2    # v2.6.13-rc2 was the last version\r
47                                  # tested that was good</literallayout>\r
48 <simpara>When you give at least one bad and one good versions, it will bisect\r
49 the revision tree and say something like:</simpara>\r
50 <literallayout>Bisecting: 675 revisions left to test after this</literallayout>\r
51 <simpara>and check out the state in the middle. Now, compile that kernel, and\r
52 boot it. Now, let&#8217;s say that this booted kernel works fine, then just\r
53 do</simpara>\r
54 <literallayout>$ git bisect good                       # this one is good</literallayout>\r
55 <simpara>which will now say</simpara>\r
56 <literallayout>Bisecting: 337 revisions left to test after this</literallayout>\r
57 <simpara>and you continue along, compiling that one, testing it, and depending\r
58 on whether it is good or bad, you say "git bisect good" or "git bisect\r
59 bad", and ask for the next bisection.</simpara>\r
60 <simpara>Until you have no more left, and you&#8217;ll have been left with the first\r
61 bad kernel rev in "refs/bisect/bad".</simpara>\r
62 </simplesect>\r
63 <simplesect id="_bisect_reset">\r
64 <title>Bisect reset</title>\r
65 <simpara>Oh, and then after you want to reset to the original head, do a</simpara>\r
66 <literallayout>$ git bisect reset</literallayout>\r
67 <simpara>to get back to the original branch, instead of being on the bisection\r
68 commit ("git bisect start" will do that for you too, actually: it will\r
69 reset the bisection state).</simpara>\r
70 </simplesect>\r
71 <simplesect id="_bisect_visualize">\r
72 <title>Bisect visualize</title>\r
73 <simpara>During the bisection process, you can say</simpara>\r
74 <literallayout>$ git bisect visualize</literallayout>\r
75 <simpara>to see the currently remaining suspects in <emphasis>gitk</emphasis>.  <literal>visualize</literal> is a bit\r
76 too long to type and <literal>view</literal> is provided as a synonym.</simpara>\r
77 <simpara>If <emphasis>DISPLAY</emphasis> environment variable is not set, <emphasis>git log</emphasis> is used\r
78 instead.  You can even give command line options such as <literal>-p</literal> and\r
79 <literal>--stat</literal>.</simpara>\r
80 <literallayout>$ git bisect view --stat</literallayout>\r
81 </simplesect>\r
82 <simplesect id="_bisect_log_and_bisect_replay">\r
83 <title>Bisect log and bisect replay</title>\r
84 <simpara>The good/bad input is logged, and</simpara>\r
85 <literallayout>$ git bisect log</literallayout>\r
86 <simpara>shows what you have done so far. You can truncate its output somewhere\r
87 and save it in a file, and run</simpara>\r
88 <literallayout>$ git bisect replay that-file</literallayout>\r
89 <simpara>if you find later you made a mistake telling good/bad about a\r
90 revision.</simpara>\r
91 </simplesect>\r
92 <simplesect id="_avoiding_to_test_a_commit">\r
93 <title>Avoiding to test a commit</title>\r
94 <simpara>If in a middle of bisect session, you know what the bisect suggested\r
95 to try next is not a good one to test (e.g. the change the commit\r
96 introduces is known not to work in your environment and you know it\r
97 does not have anything to do with the bug you are chasing), you may\r
98 want to find a near-by commit and try that instead.</simpara>\r
99 <simpara>It goes something like this:</simpara>\r
100 <literallayout>$ git bisect good/bad                   # previous round was good/bad.\r
101 Bisecting: 337 revisions left to test after this\r
102 $ git bisect visualize                  # oops, that is uninteresting.\r
103 $ git reset --hard HEAD~3               # try 3 revs before what\r
104                                         # was suggested</literallayout>\r
105 <simpara>Then compile and test the one you chose to try. After that, tell\r
106 bisect what the result was as usual.</simpara>\r
107 </simplesect>\r
108 <simplesect id="_bisect_skip">\r
109 <title>Bisect skip</title>\r
110 <simpara>Instead of choosing by yourself a nearby commit, you may just want git\r
111 to do it for you using:</simpara>\r
112 <literallayout>$ git bisect skip                 # Current version cannot be tested</literallayout>\r
113 <simpara>But computing the commit to test may be slower afterwards and git may\r
114 eventually not be able to tell the first bad among a bad and one or\r
115 more "skip"ped commits.</simpara>\r
116 <simpara>You can even skip a range of commits, instead of just one commit,\r
117 using the "<emphasis>&lt;commit1&gt;</emphasis>..<emphasis>&lt;commit2&gt;</emphasis>" notation. For example:</simpara>\r
118 <literallayout>$ git bisect skip v2.5..v2.6</literallayout>\r
119 <simpara>would mean that no commit between <literal>v2.5</literal> excluded and <literal>v2.6</literal> included\r
120 can be tested.</simpara>\r
121 <simpara>Note that if you want to also skip the first commit of a range you can\r
122 use something like:</simpara>\r
123 <literallayout>$ git bisect skip v2.5 v2.5..v2.6</literallayout>\r
124 <simpara>and the commit pointed to by <literal>v2.5</literal> will be skipped too.</simpara>\r
125 </simplesect>\r
126 <simplesect id="_cutting_down_bisection_by_giving_more_parameters_to_bisect_start">\r
127 <title>Cutting down bisection by giving more parameters to bisect start</title>\r
128 <simpara>You can further cut down the number of trials if you know what part of\r
129 the tree is involved in the problem you are tracking down, by giving\r
130 paths parameters when you say <literal>bisect start</literal>, like this:</simpara>\r
131 <literallayout>$ git bisect start -- arch/i386 include/asm-i386</literallayout>\r
132 <simpara>If you know beforehand more than one good commits, you can narrow the\r
133 bisect space down without doing the whole tree checkout every time you\r
134 give good commits. You give the bad revision immediately after <literal>start</literal>\r
135 and then you give all the good revisions you have:</simpara>\r
136 <literallayout>$ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --\r
137                    # v2.6.20-rc6 is bad\r
138                    # v2.6.20-rc4 and v2.6.20-rc1 are good</literallayout>\r
139 </simplesect>\r
140 <simplesect id="_bisect_run">\r
141 <title>Bisect run</title>\r
142 <simpara>If you have a script that can tell if the current source code is good\r
143 or bad, you can automatically bisect using:</simpara>\r
144 <literallayout>$ git bisect run my_script</literallayout>\r
145 <simpara>Note that the "run" script (<literal>my_script</literal> in the above example) should\r
146 exit with code 0 in case the current source code is good.  Exit with a\r
147 code between 1 and 127 (inclusive), except 125, if the current\r
148 source code is bad.</simpara>\r
149 <simpara>Any other exit code will abort the automatic bisect process. (A\r
150 program that does "exit(-1)" leaves $? = 255, see exit(3) manual page,\r
151 the value is chopped with "&amp; 0377".)</simpara>\r
152 <simpara>The special exit code 125 should be used when the current source code\r
153 cannot be tested. If the "run" script exits with this code, the current\r
154 revision will be skipped, see <literal>git bisect skip</literal> above.</simpara>\r
155 <simpara>You may often find that during bisect you want to have near-constant\r
156 tweaks (e.g., s/#define DEBUG 0/#define DEBUG 1/ in a header file, or\r
157 "revision that does not have this commit needs this patch applied to\r
158 work around other problem this bisection is not interested in")\r
159 applied to the revision being tested.</simpara>\r
160 <simpara>To cope with such a situation, after the inner <emphasis>git bisect</emphasis> finds the\r
161 next revision to test, with the "run" script, you can apply that tweak\r
162 before compiling, run the real test, and after the test decides if the\r
163 revision (possibly with the needed tweaks) passed the test, rewind the\r
164 tree to the pristine state.  Finally the "run" script can exit with\r
165 the status of the real test to let the "git bisect run" command loop to\r
166 determine the outcome.</simpara>\r
167 </simplesect>\r
168 </simplesect>\r
169 <simplesect id="_examples">\r
170 <title>EXAMPLES</title>\r
171 <itemizedlist>\r
172 <listitem>\r
173 <simpara>\r
174 Automatically bisect a broken build between v1.2 and HEAD:\r
175 </simpara>\r
176 <literallayout>$ git bisect start HEAD v1.2 --      # HEAD is bad, v1.2 is good\r
177 $ git bisect run make                # "make" builds the app</literallayout>\r
178 </listitem>\r
179 <listitem>\r
180 <simpara>\r
181 Automatically bisect a broken test suite:\r
182 </simpara>\r
183 <literallayout>$ cat ~/test.sh\r
184 #!/bin/sh\r
185 make || exit 125                   # this "skip"s broken builds\r
186 make test                          # "make test" runs the test suite\r
187 $ git bisect start v1.3 v1.1 --    # v1.3 is bad, v1.1 is good\r
188 $ git bisect run ~/test.sh</literallayout>\r
189 <simpara>Here we use a "test.sh" custom script. In this script, if "make"\r
190 fails, we "skip" the current commit.</simpara>\r
191 <simpara>It&#8217;s safer to use a custom script outside the repo to prevent\r
192 interactions between the bisect, make and test processes and the\r
193 script.</simpara>\r
194 <simpara>And "make test" should "exit 0", if the test suite passes, and\r
195 "exit 1" (for example) otherwise.</simpara>\r
196 </listitem>\r
197 <listitem>\r
198 <simpara>\r
199 Automatically bisect a broken test case:\r
200 </simpara>\r
201 <literallayout>$ cat ~/test.sh\r
202 #!/bin/sh\r
203 make || exit 125                     # this "skip"s broken builds\r
204 ~/check_test_case.sh                 # does the test case passes ?\r
205 $ git bisect start HEAD HEAD~10 --   # culprit is among the last 10\r
206 $ git bisect run ~/test.sh</literallayout>\r
207 <simpara>Here "check_test_case.sh" should "exit 0", if the test case passes,\r
208 and "exit 1" (for example) otherwise.</simpara>\r
209 <simpara>It&#8217;s safer if both "test.sh" and "check_test_case.sh" scripts are\r
210 outside the repo to prevent interactions between the bisect, make and\r
211 test processes and the scripts.</simpara>\r
212 </listitem>\r
213 </itemizedlist>\r
214 </simplesect>\r
215 <simplesect id="_author">\r
216 <title>Author</title>\r
217 <simpara>Written by Linus Torvalds &lt;<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>&gt;</simpara>\r
218 </simplesect>\r
219 <simplesect id="_documentation">\r
220 <title>Documentation</title>\r
221 <simpara>Documentation by Junio C Hamano and the git-list &lt;<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>&gt;.</simpara>\r
222 </simplesect>\r
223 <simplesect id="_git">\r
224 <title>GIT</title>\r
225 <simpara>Part of the <xref linkend="git(1)"/> suite</simpara>\r
226 </simplesect>\r
227 </article>\r