logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

git-bisect.1 (20854B)


  1. '\" t
  2. .\" Title: git-bisect
  3. .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
  4. .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
  5. .\" Date: 2025-03-14
  6. .\" Manual: Git Manual
  7. .\" Source: Git 2.49.0
  8. .\" Language: English
  9. .\"
  10. .TH "GIT\-BISECT" "1" "2025-03-14" "Git 2\&.49\&.0" "Git Manual"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. git-bisect \- Use binary search to find the commit that introduced a bug
  32. .SH "SYNOPSIS"
  33. .sp
  34. .nf
  35. \fIgit bisect\fR <subcommand> <options>
  36. .fi
  37. .SH "DESCRIPTION"
  38. .sp
  39. The command takes various subcommands, and different options depending on the subcommand:
  40. .sp
  41. .if n \{\
  42. .RS 4
  43. .\}
  44. .nf
  45. git bisect start [\-\-term\-(bad|new)=<term\-new> \-\-term\-(good|old)=<term\-old>]
  46. [\-\-no\-checkout] [\-\-first\-parent] [<bad> [<good>\&.\&.\&.]] [\-\-] [<pathspec>\&.\&.\&.]
  47. git bisect (bad|new|<term\-new>) [<rev>]
  48. git bisect (good|old|<term\-old>) [<rev>\&.\&.\&.]
  49. git bisect terms [\-\-term\-(good|old) | \-\-term\-(bad|new)]
  50. git bisect skip [(<rev>|<range>)\&.\&.\&.]
  51. git bisect reset [<commit>]
  52. git bisect (visualize|view)
  53. git bisect replay <logfile>
  54. git bisect log
  55. git bisect run <cmd> [<arg>\&.\&.\&.]
  56. git bisect help
  57. .fi
  58. .if n \{\
  59. .RE
  60. .\}
  61. .sp
  62. This command uses a binary search algorithm to find which commit in your project\(cqs history introduced a bug\&. You use it by first telling it a "bad" commit that is known to contain the bug, and a "good" commit that is known to be before the bug was introduced\&. Then \fBgit\fR \fBbisect\fR picks a commit between those two endpoints and asks you whether the selected commit is "good" or "bad"\&. It continues narrowing down the range until it finds the exact commit that introduced the change\&.
  63. .sp
  64. In fact, \fBgit\fR \fBbisect\fR can be used to find the commit that changed \fBany\fR property of your project; e\&.g\&., the commit that fixed a bug, or the commit that caused a benchmark\(cqs performance to improve\&. To support this more general usage, the terms "old" and "new" can be used in place of "good" and "bad", or you can choose your own terms\&. See section "Alternate terms" below for more information\&.
  65. .SS "Basic bisect commands: start, bad, good"
  66. .sp
  67. As an example, suppose you are trying to find the commit that broke a feature that was known to work in version \fBv2\&.6\&.13\-rc2\fR of your project\&. You start a bisect session as follows:
  68. .sp
  69. .if n \{\
  70. .RS 4
  71. .\}
  72. .nf
  73. $ git bisect start
  74. $ git bisect bad # Current version is bad
  75. $ git bisect good v2\&.6\&.13\-rc2 # v2\&.6\&.13\-rc2 is known to be good
  76. .fi
  77. .if n \{\
  78. .RE
  79. .\}
  80. .sp
  81. Once you have specified at least one bad and one good commit, \fBgit\fR \fBbisect\fR selects a commit in the middle of that range of history, checks it out, and outputs something similar to the following:
  82. .sp
  83. .if n \{\
  84. .RS 4
  85. .\}
  86. .nf
  87. Bisecting: 675 revisions left to test after this (roughly 10 steps)
  88. .fi
  89. .if n \{\
  90. .RE
  91. .\}
  92. .sp
  93. You should now compile the checked\-out version and test it\&. If that version works correctly, type
  94. .sp
  95. .if n \{\
  96. .RS 4
  97. .\}
  98. .nf
  99. $ git bisect good
  100. .fi
  101. .if n \{\
  102. .RE
  103. .\}
  104. .sp
  105. If that version is broken, type
  106. .sp
  107. .if n \{\
  108. .RS 4
  109. .\}
  110. .nf
  111. $ git bisect bad
  112. .fi
  113. .if n \{\
  114. .RE
  115. .\}
  116. .sp
  117. Then \fBgit\fR \fBbisect\fR will respond with something like
  118. .sp
  119. .if n \{\
  120. .RS 4
  121. .\}
  122. .nf
  123. Bisecting: 337 revisions left to test after this (roughly 9 steps)
  124. .fi
  125. .if n \{\
  126. .RE
  127. .\}
  128. .sp
  129. Keep repeating the process: compile the tree, test it, and depending on whether it is good or bad run \fBgit\fR \fBbisect\fR \fBgood\fR or \fBgit\fR \fBbisect\fR \fBbad\fR to ask for the next commit that needs testing\&.
  130. .sp
  131. Eventually there will be no more revisions left to inspect, and the command will print out a description of the first bad commit\&. The reference \fBrefs/bisect/bad\fR will be left pointing at that commit\&.
  132. .SS "Bisect reset"
  133. .sp
  134. After a bisect session, to clean up the bisection state and return to the original HEAD, issue the following command:
  135. .sp
  136. .if n \{\
  137. .RS 4
  138. .\}
  139. .nf
  140. $ git bisect reset
  141. .fi
  142. .if n \{\
  143. .RE
  144. .\}
  145. .sp
  146. By default, this will return your tree to the commit that was checked out before \fBgit\fR \fBbisect\fR \fBstart\fR\&. (A new \fBgit\fR \fBbisect\fR \fBstart\fR will also do that, as it cleans up the old bisection state\&.)
  147. .sp
  148. With an optional argument, you can return to a different commit instead:
  149. .sp
  150. .if n \{\
  151. .RS 4
  152. .\}
  153. .nf
  154. $ git bisect reset <commit>
  155. .fi
  156. .if n \{\
  157. .RE
  158. .\}
  159. .sp
  160. For example, \fBgit\fR \fBbisect\fR \fBreset\fR \fBbisect/bad\fR will check out the first bad revision, while \fBgit\fR \fBbisect\fR \fBreset\fR \fBHEAD\fR will leave you on the current bisection commit and avoid switching commits at all\&.
  161. .SS "Alternate terms"
  162. .sp
  163. Sometimes you are not looking for the commit that introduced a breakage, but rather for a commit that caused a change between some other "old" state and "new" state\&. For example, you might be looking for the commit that introduced a particular fix\&. Or you might be looking for the first commit in which the source\-code filenames were finally all converted to your company\(cqs naming standard\&. Or whatever\&.
  164. .sp
  165. In such cases it can be very confusing to use the terms "good" and "bad" to refer to "the state before the change" and "the state after the change"\&. So instead, you can use the terms "old" and "new", respectively, in place of "good" and "bad"\&. (But note that you cannot mix "good" and "bad" with "old" and "new" in a single session\&.)
  166. .sp
  167. In this more general usage, you provide \fBgit\fR \fBbisect\fR with a "new" commit that has some property and an "old" commit that doesn\(cqt have that property\&. Each time \fBgit\fR \fBbisect\fR checks out a commit, you test if that commit has the property\&. If it does, mark the commit as "new"; otherwise, mark it as "old"\&. When the bisection is done, \fBgit\fR \fBbisect\fR will report which commit introduced the property\&.
  168. .sp
  169. To use "old" and "new" instead of "good" and bad, you must run \fBgit\fR \fBbisect\fR \fBstart\fR without commits as argument and then run the following commands to add the commits:
  170. .sp
  171. .if n \{\
  172. .RS 4
  173. .\}
  174. .nf
  175. git bisect old [<rev>]
  176. .fi
  177. .if n \{\
  178. .RE
  179. .\}
  180. .sp
  181. to indicate that a commit was before the sought change, or
  182. .sp
  183. .if n \{\
  184. .RS 4
  185. .\}
  186. .nf
  187. git bisect new [<rev>\&.\&.\&.]
  188. .fi
  189. .if n \{\
  190. .RE
  191. .\}
  192. .sp
  193. to indicate that it was after\&.
  194. .sp
  195. To get a reminder of the currently used terms, use
  196. .sp
  197. .if n \{\
  198. .RS 4
  199. .\}
  200. .nf
  201. git bisect terms
  202. .fi
  203. .if n \{\
  204. .RE
  205. .\}
  206. .sp
  207. You can get just the old term with \fBgit\fR \fBbisect\fR \fBterms\fR \fB\-\-term\-old\fR or \fBgit\fR \fBbisect\fR \fBterms\fR \fB\-\-term\-good\fR; \fBgit\fR \fBbisect\fR \fBterms\fR \fB\-\-term\-new\fR and \fBgit\fR \fBbisect\fR \fBterms\fR \fB\-\-term\-bad\fR can be used to learn how to call the commits more recent than the sought change\&.
  208. .sp
  209. If you would like to use your own terms instead of "bad"/"good" or "new"/"old", you can choose any names you like (except existing bisect subcommands like \fBreset\fR, \fBstart\fR, \&...\:) by starting the bisection using
  210. .sp
  211. .if n \{\
  212. .RS 4
  213. .\}
  214. .nf
  215. git bisect start \-\-term\-old <term\-old> \-\-term\-new <term\-new>
  216. .fi
  217. .if n \{\
  218. .RE
  219. .\}
  220. .sp
  221. For example, if you are looking for a commit that introduced a performance regression, you might use
  222. .sp
  223. .if n \{\
  224. .RS 4
  225. .\}
  226. .nf
  227. git bisect start \-\-term\-old fast \-\-term\-new slow
  228. .fi
  229. .if n \{\
  230. .RE
  231. .\}
  232. .sp
  233. Or if you are looking for the commit that fixed a bug, you might use
  234. .sp
  235. .if n \{\
  236. .RS 4
  237. .\}
  238. .nf
  239. git bisect start \-\-term\-new fixed \-\-term\-old broken
  240. .fi
  241. .if n \{\
  242. .RE
  243. .\}
  244. .sp
  245. Then, use \fBgit\fR \fBbisect\fR \fI<term\-old>\fR and \fBgit\fR \fBbisect\fR \fI<term\-new>\fR instead of \fBgit\fR \fBbisect\fR \fBgood\fR and \fBgit\fR \fBbisect\fR \fBbad\fR to mark commits\&.
  246. .SS "Bisect visualize/view"
  247. .sp
  248. To see the currently remaining suspects in \fIgitk\fR, issue the following command during the bisection process (the subcommand \fBview\fR can be used as an alternative to \fBvisualize\fR):
  249. .sp
  250. .if n \{\
  251. .RS 4
  252. .\}
  253. .nf
  254. $ git bisect visualize
  255. .fi
  256. .if n \{\
  257. .RE
  258. .\}
  259. .sp
  260. Git detects a graphical environment through various environment variables: \fBDISPLAY\fR, which is set in X Window System environments on Unix systems\&. \fBSESSIONNAME\fR, which is set under Cygwin in interactive desktop sessions\&. \fBMSYSTEM\fR, which is set under Msys2 and Git for Windows\&. \fBSECURITYSESSIONID\fR, which may be set on macOS in interactive desktop sessions\&.
  261. .sp
  262. If none of these environment variables is set, \fIgit log\fR is used instead\&. You can also give command\-line options such as \fB\-p\fR and \fB\-\-stat\fR\&.
  263. .sp
  264. .if n \{\
  265. .RS 4
  266. .\}
  267. .nf
  268. $ git bisect visualize \-\-stat
  269. .fi
  270. .if n \{\
  271. .RE
  272. .\}
  273. .SS "Bisect log and bisect replay"
  274. .sp
  275. After having marked revisions as good or bad, issue the following command to show what has been done so far:
  276. .sp
  277. .if n \{\
  278. .RS 4
  279. .\}
  280. .nf
  281. $ git bisect log
  282. .fi
  283. .if n \{\
  284. .RE
  285. .\}
  286. .sp
  287. If you discover that you made a mistake in specifying the status of a revision, you can save the output of this command to a file, edit it to remove the incorrect entries, and then issue the following commands to return to a corrected state:
  288. .sp
  289. .if n \{\
  290. .RS 4
  291. .\}
  292. .nf
  293. $ git bisect reset
  294. $ git bisect replay that\-file
  295. .fi
  296. .if n \{\
  297. .RE
  298. .\}
  299. .SS "Avoiding testing a commit"
  300. .sp
  301. If, in the middle of a bisect session, you know that the suggested revision is not a good one to test (e\&.g\&. it fails to build and you know that the failure does not have anything to do with the bug you are chasing), you can manually select a nearby commit and test that one instead\&.
  302. .sp
  303. For example:
  304. .sp
  305. .if n \{\
  306. .RS 4
  307. .\}
  308. .nf
  309. $ git bisect good/bad # previous round was good or bad\&.
  310. Bisecting: 337 revisions left to test after this (roughly 9 steps)
  311. $ git bisect visualize # oops, that is uninteresting\&.
  312. $ git reset \-\-hard HEAD~3 # try 3 revisions before what
  313. # was suggested
  314. .fi
  315. .if n \{\
  316. .RE
  317. .\}
  318. .sp
  319. Then compile and test the chosen revision, and afterwards mark the revision as good or bad in the usual manner\&.
  320. .SS "Bisect skip"
  321. .sp
  322. Instead of choosing a nearby commit by yourself, you can ask Git to do it for you by issuing the command:
  323. .sp
  324. .if n \{\
  325. .RS 4
  326. .\}
  327. .nf
  328. $ git bisect skip # Current version cannot be tested
  329. .fi
  330. .if n \{\
  331. .RE
  332. .\}
  333. .sp
  334. However, if you skip a commit adjacent to the one you are looking for, Git will be unable to tell exactly which of those commits was the first bad one\&.
  335. .sp
  336. You can also skip a range of commits, instead of just one commit, using range notation\&. For example:
  337. .sp
  338. .if n \{\
  339. .RS 4
  340. .\}
  341. .nf
  342. $ git bisect skip v2\&.5\&.\&.v2\&.6
  343. .fi
  344. .if n \{\
  345. .RE
  346. .\}
  347. .sp
  348. This tells the bisect process that no commit after \fBv2\&.5\fR, up to and including \fBv2\&.6\fR, should be tested\&.
  349. .sp
  350. Note that if you also want to skip the first commit of the range you would issue the command:
  351. .sp
  352. .if n \{\
  353. .RS 4
  354. .\}
  355. .nf
  356. $ git bisect skip v2\&.5 v2\&.5\&.\&.v2\&.6
  357. .fi
  358. .if n \{\
  359. .RE
  360. .\}
  361. .sp
  362. This tells the bisect process that the commits between \fBv2\&.5\fR and \fBv2\&.6\fR (inclusive) should be skipped\&.
  363. .SS "Cutting down bisection by giving more parameters to bisect start"
  364. .sp
  365. You can further cut down the number of trials, if you know what part of the tree is involved in the problem you are tracking down, by specifying pathspec parameters when issuing the \fBbisect\fR \fBstart\fR command:
  366. .sp
  367. .if n \{\
  368. .RS 4
  369. .\}
  370. .nf
  371. $ git bisect start \-\- arch/i386 include/asm\-i386
  372. .fi
  373. .if n \{\
  374. .RE
  375. .\}
  376. .sp
  377. If you know beforehand more than one good commit, you can narrow the bisect space down by specifying all of the good commits immediately after the bad commit when issuing the \fBbisect\fR \fBstart\fR command:
  378. .sp
  379. .if n \{\
  380. .RS 4
  381. .\}
  382. .nf
  383. $ git bisect start v2\&.6\&.20\-rc6 v2\&.6\&.20\-rc4 v2\&.6\&.20\-rc1 \-\-
  384. # v2\&.6\&.20\-rc6 is bad
  385. # v2\&.6\&.20\-rc4 and v2\&.6\&.20\-rc1 are good
  386. .fi
  387. .if n \{\
  388. .RE
  389. .\}
  390. .SS "Bisect run"
  391. .sp
  392. If you have a script that can tell if the current source code is good or bad, you can bisect by issuing the command:
  393. .sp
  394. .if n \{\
  395. .RS 4
  396. .\}
  397. .nf
  398. $ git bisect run my_script arguments
  399. .fi
  400. .if n \{\
  401. .RE
  402. .\}
  403. .sp
  404. Note that the script (\fBmy_script\fR in the above example) should exit with code 0 if the current source code is good/old, and exit with a code between 1 and 127 (inclusive), except 125, if the current source code is bad/new\&.
  405. .sp
  406. Any other exit code will abort the bisect process\&. It should be noted that a program that terminates via \fBexit\fR(\fB\-1\fR) leaves $? = 255, (see the exit(3) manual page), as the value is chopped with & \fB0377\fR\&.
  407. .sp
  408. The special exit code 125 should be used when the current source code cannot be tested\&. If the script exits with this code, the current revision will be skipped (see \fBgit\fR \fBbisect\fR \fBskip\fR above)\&. 125 was chosen as the highest sensible value to use for this purpose, because 126 and 127 are used by POSIX shells to signal specific error status (127 is for command not found, 126 is for command found but not executable\(em\:these details do not matter, as they are normal errors in the script, as far as \fBbisect\fR \fBrun\fR is concerned)\&.
  409. .sp
  410. You may often find that during a bisect session you want to have temporary modifications (e\&.g\&. s/#define DEBUG 0/#define DEBUG 1/ in a header file, or "revision that does not have this commit needs this patch applied to work around another problem this bisection is not interested in") applied to the revision being tested\&.
  411. .sp
  412. To cope with such a situation, after the inner \fIgit bisect\fR finds the next revision to test, the script can apply the patch before compiling, run the real test, and afterwards decide if the revision (possibly with the needed patch) passed the test and then rewind the tree to the pristine state\&. Finally the script should exit with the status of the real test to let the \fBgit\fR \fBbisect\fR \fBrun\fR command loop determine the eventual outcome of the bisect session\&.
  413. .SH "OPTIONS"
  414. .PP
  415. \-\-no\-checkout
  416. .RS 4
  417. Do not checkout the new working tree at each iteration of the bisection process\&. Instead just update the reference named
  418. \fBBISECT_HEAD\fR
  419. to make it point to the commit that should be tested\&.
  420. .sp
  421. This option may be useful when the test you would perform in each step does not require a checked out tree\&.
  422. .sp
  423. If the repository is bare,
  424. \fB\-\-no\-checkout\fR
  425. is assumed\&.
  426. .RE
  427. .PP
  428. \-\-first\-parent
  429. .RS 4
  430. Follow only the first parent commit upon seeing a merge commit\&.
  431. .sp
  432. In detecting regressions introduced through the merging of a branch, the merge commit will be identified as introduction of the bug and its ancestors will be ignored\&.
  433. .sp
  434. This option is particularly useful in avoiding false positives when a merged branch contained broken or non\-buildable commits, but the merge itself was OK\&.
  435. .RE
  436. .SH "EXAMPLES"
  437. .sp
  438. .RS 4
  439. .ie n \{\
  440. \h'-04'\(bu\h'+03'\c
  441. .\}
  442. .el \{\
  443. .sp -1
  444. .IP \(bu 2.3
  445. .\}
  446. Automatically bisect a broken build between v1\&.2 and HEAD:
  447. .sp
  448. .if n \{\
  449. .RS 4
  450. .\}
  451. .nf
  452. $ git bisect start HEAD v1\&.2 \-\- # HEAD is bad, v1\&.2 is good
  453. $ git bisect run make # "make" builds the app
  454. $ git bisect reset # quit the bisect session
  455. .fi
  456. .if n \{\
  457. .RE
  458. .\}
  459. .RE
  460. .sp
  461. .RS 4
  462. .ie n \{\
  463. \h'-04'\(bu\h'+03'\c
  464. .\}
  465. .el \{\
  466. .sp -1
  467. .IP \(bu 2.3
  468. .\}
  469. Automatically bisect a test failure between origin and HEAD:
  470. .sp
  471. .if n \{\
  472. .RS 4
  473. .\}
  474. .nf
  475. $ git bisect start HEAD origin \-\- # HEAD is bad, origin is good
  476. $ git bisect run make test # "make test" builds and tests
  477. $ git bisect reset # quit the bisect session
  478. .fi
  479. .if n \{\
  480. .RE
  481. .\}
  482. .RE
  483. .sp
  484. .RS 4
  485. .ie n \{\
  486. \h'-04'\(bu\h'+03'\c
  487. .\}
  488. .el \{\
  489. .sp -1
  490. .IP \(bu 2.3
  491. .\}
  492. Automatically bisect a broken test case:
  493. .sp
  494. .if n \{\
  495. .RS 4
  496. .\}
  497. .nf
  498. $ cat ~/test\&.sh
  499. #!/bin/sh
  500. make || exit 125 # this skips broken builds
  501. ~/check_test_case\&.sh # does the test case pass?
  502. $ git bisect start HEAD HEAD~10 \-\- # culprit is among the last 10
  503. $ git bisect run ~/test\&.sh
  504. $ git bisect reset # quit the bisect session
  505. .fi
  506. .if n \{\
  507. .RE
  508. .\}
  509. .sp
  510. Here we use a
  511. \fBtest\&.sh\fR
  512. custom script\&. In this script, if
  513. \fBmake\fR
  514. fails, we skip the current commit\&.
  515. \fBcheck_test_case\&.sh\fR
  516. should
  517. \fBexit\fR
  518. \fB0\fR
  519. if the test case passes, and
  520. \fBexit\fR
  521. \fB1\fR
  522. otherwise\&.
  523. .sp
  524. It is safer if both
  525. \fBtest\&.sh\fR
  526. and
  527. \fBcheck_test_case\&.sh\fR
  528. are outside the repository to prevent interactions between the bisect, make and test processes and the scripts\&.
  529. .RE
  530. .sp
  531. .RS 4
  532. .ie n \{\
  533. \h'-04'\(bu\h'+03'\c
  534. .\}
  535. .el \{\
  536. .sp -1
  537. .IP \(bu 2.3
  538. .\}
  539. Automatically bisect with temporary modifications (hot\-fix):
  540. .sp
  541. .if n \{\
  542. .RS 4
  543. .\}
  544. .nf
  545. $ cat ~/test\&.sh
  546. #!/bin/sh
  547. # tweak the working tree by merging the hot\-fix branch
  548. # and then attempt a build
  549. if git merge \-\-no\-commit \-\-no\-ff hot\-fix &&
  550. make
  551. then
  552. # run project specific test and report its status
  553. ~/check_test_case\&.sh
  554. status=$?
  555. else
  556. # tell the caller this is untestable
  557. status=125
  558. fi
  559. # undo the tweak to allow clean flipping to the next commit
  560. git reset \-\-hard
  561. # return control
  562. exit $status
  563. .fi
  564. .if n \{\
  565. .RE
  566. .\}
  567. .sp
  568. This applies modifications from a hot\-fix branch before each test run, e\&.g\&. in case your build or test environment changed so that older revisions may need a fix which newer ones have already\&. (Make sure the hot\-fix branch is based off a commit which is contained in all revisions which you are bisecting, so that the merge does not pull in too much, or use
  569. \fBgit\fR
  570. \fBcherry\-pick\fR
  571. instead of
  572. \fBgit\fR
  573. \fBmerge\fR\&.)
  574. .RE
  575. .sp
  576. .RS 4
  577. .ie n \{\
  578. \h'-04'\(bu\h'+03'\c
  579. .\}
  580. .el \{\
  581. .sp -1
  582. .IP \(bu 2.3
  583. .\}
  584. Automatically bisect a broken test case:
  585. .sp
  586. .if n \{\
  587. .RS 4
  588. .\}
  589. .nf
  590. $ git bisect start HEAD HEAD~10 \-\- # culprit is among the last 10
  591. $ git bisect run sh \-c "make || exit 125; ~/check_test_case\&.sh"
  592. $ git bisect reset # quit the bisect session
  593. .fi
  594. .if n \{\
  595. .RE
  596. .\}
  597. .sp
  598. This shows that you can do without a run script if you write the test on a single line\&.
  599. .RE
  600. .sp
  601. .RS 4
  602. .ie n \{\
  603. \h'-04'\(bu\h'+03'\c
  604. .\}
  605. .el \{\
  606. .sp -1
  607. .IP \(bu 2.3
  608. .\}
  609. Locate a good region of the object graph in a damaged repository
  610. .sp
  611. .if n \{\
  612. .RS 4
  613. .\}
  614. .nf
  615. $ git bisect start HEAD <known\-good\-commit> [ <boundary\-commit> \&.\&.\&. ] \-\-no\-checkout
  616. $ git bisect run sh \-c \*(Aq
  617. GOOD=$(git for\-each\-ref "\-\-format=%(objectname)" refs/bisect/good\-*) &&
  618. git rev\-list \-\-objects BISECT_HEAD \-\-not $GOOD >tmp\&.$$ &&
  619. git pack\-objects \-\-stdout >/dev/null <tmp\&.$$
  620. rc=$?
  621. rm \-f tmp\&.$$
  622. test $rc = 0\*(Aq
  623. $ git bisect reset # quit the bisect session
  624. .fi
  625. .if n \{\
  626. .RE
  627. .\}
  628. .sp
  629. In this case, when
  630. \fIgit bisect run\fR
  631. finishes, bisect/bad will refer to a commit that has at least one parent whose reachable graph is fully traversable in the sense required by
  632. \fIgit pack objects\fR\&.
  633. .RE
  634. .sp
  635. .RS 4
  636. .ie n \{\
  637. \h'-04'\(bu\h'+03'\c
  638. .\}
  639. .el \{\
  640. .sp -1
  641. .IP \(bu 2.3
  642. .\}
  643. Look for a fix instead of a regression in the code
  644. .sp
  645. .if n \{\
  646. .RS 4
  647. .\}
  648. .nf
  649. $ git bisect start
  650. $ git bisect new HEAD # current commit is marked as new
  651. $ git bisect old HEAD~10 # the tenth commit from now is marked as old
  652. .fi
  653. .if n \{\
  654. .RE
  655. .\}
  656. .sp
  657. or:
  658. .RE
  659. .sp
  660. .if n \{\
  661. .RS 4
  662. .\}
  663. .nf
  664. $ git bisect start \-\-term\-old broken \-\-term\-new fixed
  665. $ git bisect fixed
  666. $ git bisect broken HEAD~10
  667. .fi
  668. .if n \{\
  669. .RE
  670. .\}
  671. .SS "Getting help"
  672. .sp
  673. Use \fBgit\fR \fBbisect\fR to get a short usage description, and \fBgit\fR \fBbisect\fR \fBhelp\fR or \fBgit\fR \fBbisect\fR \fB\-h\fR to get a long usage description\&.
  674. .SH "SEE ALSO"
  675. .sp
  676. \m[blue]\fBFighting regressions with git bisect\fR\m[]\&\s-2\u[1]\d\s+2, \fBgit-blame\fR(1)\&.
  677. .SH "GIT"
  678. .sp
  679. Part of the \fBgit\fR(1) suite
  680. .SH "NOTES"
  681. .IP " 1." 4
  682. Fighting regressions with git bisect
  683. .RS 4
  684. \%git-htmldocs/git-bisect-lk2009.html
  685. .RE