Junio C Hamano | 215a7ad | 2005-09-07 17:26:23 -0700 | [diff] [blame] | 1 | git-bisect(1) |
| 2 | ============= |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 3 | |
| 4 | NAME |
| 5 | ---- |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 6 | git-bisect - Use binary search to find the commit that introduced a bug |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
Martin von Zweigbergk | 7791a1d | 2011-07-01 22:38:26 -0400 | [diff] [blame] | 11 | [verse] |
Junio C Hamano | a6080a0 | 2007-06-07 00:04:01 -0700 | [diff] [blame] | 12 | 'git bisect' <subcommand> <options> |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 13 | |
| 14 | DESCRIPTION |
| 15 | ----------- |
Christian Couder | fed820a | 2007-03-24 06:31:49 +0100 | [diff] [blame] | 16 | The command takes various subcommands, and different options depending |
| 17 | on the subcommand: |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 18 | |
Matthieu Moy | 06e6a74 | 2015-06-29 17:40:35 +0200 | [diff] [blame] | 19 | git bisect start [--term-{old,good}=<term> --term-{new,bad}=<term>] |
| 20 | [--no-checkout] [<bad> [<good>...]] [--] [<paths>...] |
Christian Couder | 3f05402 | 2017-01-13 15:44:05 +0100 | [diff] [blame] | 21 | git bisect (bad|new|<term-new>) [<rev>] |
| 22 | git bisect (good|old|<term-old>) [<rev>...] |
Matthieu Moy | 21b55e3 | 2015-06-29 17:40:34 +0200 | [diff] [blame] | 23 | git bisect terms [--term-good | --term-bad] |
Christian Couder | 5413812 | 2008-12-02 14:53:51 +0100 | [diff] [blame] | 24 | git bisect skip [(<rev>|<range>)...] |
Anders Kaseorg | 6b87ce2 | 2009-10-13 17:02:24 -0400 | [diff] [blame] | 25 | git bisect reset [<commit>] |
Robert P. J. Day | dbc349b | 2017-11-12 04:30:38 -0500 | [diff] [blame] | 26 | git bisect (visualize|view) |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 27 | git bisect replay <logfile> |
| 28 | git bisect log |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 29 | git bisect run <cmd>... |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 30 | git bisect help |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 31 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 32 | This command uses a binary search algorithm to find which commit in |
| 33 | your project's history introduced a bug. You use it by first telling |
| 34 | it a "bad" commit that is known to contain the bug, and a "good" |
| 35 | commit that is known to be before the bug was introduced. Then `git |
| 36 | bisect` picks a commit between those two endpoints and asks you |
| 37 | whether the selected commit is "good" or "bad". It continues narrowing |
| 38 | down the range until it finds the exact commit that introduced the |
| 39 | change. |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 40 | |
Antoine Delaite | 21e5cfd | 2015-06-29 17:40:33 +0200 | [diff] [blame] | 41 | In fact, `git bisect` can be used to find the commit that changed |
| 42 | *any* property of your project; e.g., the commit that fixed a bug, or |
| 43 | the commit that caused a benchmark's performance to improve. To |
| 44 | support this more general usage, the terms "old" and "new" can be used |
Matthieu Moy | 06e6a74 | 2015-06-29 17:40:35 +0200 | [diff] [blame] | 45 | in place of "good" and "bad", or you can choose your own terms. See |
Antoine Delaite | 21e5cfd | 2015-06-29 17:40:33 +0200 | [diff] [blame] | 46 | section "Alternate terms" below for more information. |
| 47 | |
Christian Couder | 1207f9e | 2007-03-24 06:30:33 +0100 | [diff] [blame] | 48 | Basic bisect commands: start, bad, good |
| 49 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 50 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 51 | As an example, suppose you are trying to find the commit that broke a |
| 52 | feature that was known to work in version `v2.6.13-rc2` of your |
| 53 | project. You start a bisect session as follows: |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 54 | |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 55 | ------------------------------------------------ |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 56 | $ git bisect start |
Christian Couder | 6cea055 | 2007-03-24 06:32:05 +0100 | [diff] [blame] | 57 | $ git bisect bad # Current version is bad |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 58 | $ git bisect good v2.6.13-rc2 # v2.6.13-rc2 is known to be good |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 59 | ------------------------------------------------ |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 60 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 61 | Once you have specified at least one bad and one good commit, `git |
| 62 | bisect` selects a commit in the middle of that range of history, |
| 63 | checks it out, and outputs something similar to the following: |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 64 | |
| 65 | ------------------------------------------------ |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 66 | Bisecting: 675 revisions left to test after this (roughly 10 steps) |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 67 | ------------------------------------------------ |
| 68 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 69 | You should now compile the checked-out version and test it. If that |
| 70 | version works correctly, type |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 71 | |
| 72 | ------------------------------------------------ |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 73 | $ git bisect good |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 74 | ------------------------------------------------ |
| 75 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 76 | If that version is broken, type |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 77 | |
| 78 | ------------------------------------------------ |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 79 | $ git bisect bad |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 80 | ------------------------------------------------ |
| 81 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 82 | Then `git bisect` will respond with something like |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 83 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 84 | ------------------------------------------------ |
| 85 | Bisecting: 337 revisions left to test after this (roughly 9 steps) |
| 86 | ------------------------------------------------ |
| 87 | |
| 88 | Keep repeating the process: compile the tree, test it, and depending |
| 89 | on whether it is good or bad run `git bisect good` or `git bisect bad` |
| 90 | to ask for the next commit that needs testing. |
| 91 | |
| 92 | Eventually there will be no more revisions left to inspect, and the |
| 93 | command will print out a description of the first bad commit. The |
| 94 | reference `refs/bisect/bad` will be left pointing at that commit. |
| 95 | |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 96 | |
Christian Couder | 1207f9e | 2007-03-24 06:30:33 +0100 | [diff] [blame] | 97 | Bisect reset |
| 98 | ~~~~~~~~~~~~ |
| 99 | |
Anders Kaseorg | 6b87ce2 | 2009-10-13 17:02:24 -0400 | [diff] [blame] | 100 | After a bisect session, to clean up the bisection state and return to |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 101 | the original HEAD, issue the following command: |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 102 | |
| 103 | ------------------------------------------------ |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 104 | $ git bisect reset |
Junio C Hamano | f85a419 | 2005-08-29 17:21:06 -0700 | [diff] [blame] | 105 | ------------------------------------------------ |
| 106 | |
Anders Kaseorg | 6b87ce2 | 2009-10-13 17:02:24 -0400 | [diff] [blame] | 107 | By default, this will return your tree to the commit that was checked |
| 108 | out before `git bisect start`. (A new `git bisect start` will also do |
| 109 | that, as it cleans up the old bisection state.) |
| 110 | |
| 111 | With an optional argument, you can return to a different commit |
| 112 | instead: |
| 113 | |
| 114 | ------------------------------------------------ |
| 115 | $ git bisect reset <commit> |
| 116 | ------------------------------------------------ |
| 117 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 118 | For example, `git bisect reset bisect/bad` will check out the first |
| 119 | bad revision, while `git bisect reset HEAD` will leave you on the |
| 120 | current bisection commit and avoid switching commits at all. |
| 121 | |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 122 | |
Antoine Delaite | 21e5cfd | 2015-06-29 17:40:33 +0200 | [diff] [blame] | 123 | Alternate terms |
| 124 | ~~~~~~~~~~~~~~~ |
| 125 | |
| 126 | Sometimes you are not looking for the commit that introduced a |
| 127 | breakage, but rather for a commit that caused a change between some |
| 128 | other "old" state and "new" state. For example, you might be looking |
| 129 | for the commit that introduced a particular fix. Or you might be |
| 130 | looking for the first commit in which the source-code filenames were |
| 131 | finally all converted to your company's naming standard. Or whatever. |
| 132 | |
| 133 | In such cases it can be very confusing to use the terms "good" and |
| 134 | "bad" to refer to "the state before the change" and "the state after |
| 135 | the change". So instead, you can use the terms "old" and "new", |
| 136 | respectively, in place of "good" and "bad". (But note that you cannot |
| 137 | mix "good" and "bad" with "old" and "new" in a single session.) |
| 138 | |
| 139 | In this more general usage, you provide `git bisect` with a "new" |
Quentin Pradet | 60b091c | 2017-04-01 10:40:56 +0400 | [diff] [blame] | 140 | commit that has some property and an "old" commit that doesn't have that |
Antoine Delaite | 21e5cfd | 2015-06-29 17:40:33 +0200 | [diff] [blame] | 141 | property. Each time `git bisect` checks out a commit, you test if that |
| 142 | commit has the property. If it does, mark the commit as "new"; |
| 143 | otherwise, mark it as "old". When the bisection is done, `git bisect` |
| 144 | will report which commit introduced the property. |
| 145 | |
| 146 | To use "old" and "new" instead of "good" and bad, you must run `git |
| 147 | bisect start` without commits as argument and then run the following |
| 148 | commands to add the commits: |
| 149 | |
| 150 | ------------------------------------------------ |
| 151 | git bisect old [<rev>] |
| 152 | ------------------------------------------------ |
| 153 | |
| 154 | to indicate that a commit was before the sought change, or |
| 155 | |
| 156 | ------------------------------------------------ |
| 157 | git bisect new [<rev>...] |
| 158 | ------------------------------------------------ |
| 159 | |
| 160 | to indicate that it was after. |
| 161 | |
Matthieu Moy | 21b55e3 | 2015-06-29 17:40:34 +0200 | [diff] [blame] | 162 | To get a reminder of the currently used terms, use |
| 163 | |
| 164 | ------------------------------------------------ |
| 165 | git bisect terms |
| 166 | ------------------------------------------------ |
| 167 | |
Anders Kaseorg | bbd374d | 2018-04-06 16:21:19 -0400 | [diff] [blame] | 168 | You can get just the old (respectively new) term with `git bisect terms |
| 169 | --term-old` or `git bisect terms --term-good`. |
Matthieu Moy | 21b55e3 | 2015-06-29 17:40:34 +0200 | [diff] [blame] | 170 | |
Matthieu Moy | 06e6a74 | 2015-06-29 17:40:35 +0200 | [diff] [blame] | 171 | If you would like to use your own terms instead of "bad"/"good" or |
| 172 | "new"/"old", you can choose any names you like (except existing bisect |
| 173 | subcommands like `reset`, `start`, ...) by starting the |
| 174 | bisection using |
| 175 | |
| 176 | ------------------------------------------------ |
| 177 | git bisect start --term-old <term-old> --term-new <term-new> |
| 178 | ------------------------------------------------ |
| 179 | |
| 180 | For example, if you are looking for a commit that introduced a |
| 181 | performance regression, you might use |
| 182 | |
| 183 | ------------------------------------------------ |
| 184 | git bisect start --term-old fast --term-new slow |
| 185 | ------------------------------------------------ |
| 186 | |
| 187 | Or if you are looking for the commit that fixed a bug, you might use |
| 188 | |
| 189 | ------------------------------------------------ |
| 190 | git bisect start --term-new fixed --term-old broken |
| 191 | ------------------------------------------------ |
| 192 | |
| 193 | Then, use `git bisect <term-old>` and `git bisect <term-new>` instead |
| 194 | of `git bisect good` and `git bisect bad` to mark commits. |
| 195 | |
Robert P. J. Day | dbc349b | 2017-11-12 04:30:38 -0500 | [diff] [blame] | 196 | Bisect visualize/view |
| 197 | ~~~~~~~~~~~~~~~~~~~~~ |
Christian Couder | 1207f9e | 2007-03-24 06:30:33 +0100 | [diff] [blame] | 198 | |
David J. Mellor | a42dea3 | 2009-03-22 20:11:10 -0700 | [diff] [blame] | 199 | To see the currently remaining suspects in 'gitk', issue the following |
Robert P. J. Day | dbc349b | 2017-11-12 04:30:38 -0500 | [diff] [blame] | 200 | command during the bisection process (the subcommand `view` can be used |
| 201 | as an alternative to `visualize`): |
Junio C Hamano | 8db9307 | 2005-08-30 13:51:01 -0700 | [diff] [blame] | 202 | |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 203 | ------------ |
| 204 | $ git bisect visualize |
| 205 | ------------ |
Junio C Hamano | 8db9307 | 2005-08-30 13:51:01 -0700 | [diff] [blame] | 206 | |
Tom Russello | 47d81b5 | 2016-06-08 00:35:07 +0200 | [diff] [blame] | 207 | If the `DISPLAY` environment variable is not set, 'git log' is used |
Jason St. John | 06ab60c | 2014-05-21 14:52:26 -0400 | [diff] [blame] | 208 | instead. You can also give command-line options such as `-p` and |
Junio C Hamano | 235997c | 2007-12-07 02:25:34 -0800 | [diff] [blame] | 209 | `--stat`. |
| 210 | |
| 211 | ------------ |
Robert P. J. Day | dbc349b | 2017-11-12 04:30:38 -0500 | [diff] [blame] | 212 | $ git bisect visualize --stat |
Junio C Hamano | 235997c | 2007-12-07 02:25:34 -0800 | [diff] [blame] | 213 | ------------ |
Junio C Hamano | 8db9307 | 2005-08-30 13:51:01 -0700 | [diff] [blame] | 214 | |
Christian Couder | 1207f9e | 2007-03-24 06:30:33 +0100 | [diff] [blame] | 215 | Bisect log and bisect replay |
| 216 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 217 | |
David J. Mellor | a42dea3 | 2009-03-22 20:11:10 -0700 | [diff] [blame] | 218 | After having marked revisions as good or bad, issue the following |
David J. Mellor | 4306bcb | 2009-03-19 20:35:34 -0700 | [diff] [blame] | 219 | command to show what has been done so far: |
Christian Couder | fed820a | 2007-03-24 06:31:49 +0100 | [diff] [blame] | 220 | |
| 221 | ------------ |
| 222 | $ git bisect log |
| 223 | ------------ |
| 224 | |
David J. Mellor | 4306bcb | 2009-03-19 20:35:34 -0700 | [diff] [blame] | 225 | If you discover that you made a mistake in specifying the status of a |
| 226 | revision, you can save the output of this command to a file, edit it to |
| 227 | remove the incorrect entries, and then issue the following commands to |
| 228 | return to a corrected state: |
Junio C Hamano | b595ed1 | 2005-09-10 15:23:09 -0700 | [diff] [blame] | 229 | |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 230 | ------------ |
David J. Mellor | ee9cf14 | 2009-03-19 00:00:12 -0700 | [diff] [blame] | 231 | $ git bisect reset |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 232 | $ git bisect replay that-file |
| 233 | ------------ |
Junio C Hamano | b595ed1 | 2005-09-10 15:23:09 -0700 | [diff] [blame] | 234 | |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 235 | Avoiding testing a commit |
Christian Couder | 1207f9e | 2007-03-24 06:30:33 +0100 | [diff] [blame] | 236 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 237 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 238 | If, in the middle of a bisect session, you know that the suggested |
| 239 | revision is not a good one to test (e.g. it fails to build and you |
| 240 | know that the failure does not have anything to do with the bug you |
| 241 | are chasing), you can manually select a nearby commit and test that |
| 242 | one instead. |
Christian Couder | fed820a | 2007-03-24 06:31:49 +0100 | [diff] [blame] | 243 | |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 244 | For example: |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 245 | |
| 246 | ------------ |
David J. Mellor | ee9cf14 | 2009-03-19 00:00:12 -0700 | [diff] [blame] | 247 | $ git bisect good/bad # previous round was good or bad. |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 248 | Bisecting: 337 revisions left to test after this (roughly 9 steps) |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 249 | $ git bisect visualize # oops, that is uninteresting. |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 250 | $ git reset --hard HEAD~3 # try 3 revisions before what |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 251 | # was suggested |
| 252 | ------------ |
| 253 | |
David J. Mellor | 19fa5e8 | 2009-03-25 20:44:44 -0700 | [diff] [blame] | 254 | Then compile and test the chosen revision, and afterwards mark |
David J. Mellor | a42dea3 | 2009-03-22 20:11:10 -0700 | [diff] [blame] | 255 | the revision as good or bad in the usual manner. |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 256 | |
Christian Couder | c39ce91 | 2007-10-22 07:49:23 +0200 | [diff] [blame] | 257 | Bisect skip |
Junio C Hamano | 142d035 | 2015-10-22 10:09:07 -0700 | [diff] [blame] | 258 | ~~~~~~~~~~~ |
Christian Couder | c39ce91 | 2007-10-22 07:49:23 +0200 | [diff] [blame] | 259 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 260 | Instead of choosing a nearby commit by yourself, you can ask Git to do |
| 261 | it for you by issuing the command: |
Christian Couder | c39ce91 | 2007-10-22 07:49:23 +0200 | [diff] [blame] | 262 | |
| 263 | ------------ |
| 264 | $ git bisect skip # Current version cannot be tested |
| 265 | ------------ |
| 266 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 267 | However, if you skip a commit adjacent to the one you are looking for, |
| 268 | Git will be unable to tell exactly which of those commits was the |
| 269 | first bad one. |
Christian Couder | c39ce91 | 2007-10-22 07:49:23 +0200 | [diff] [blame] | 270 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 271 | You can also skip a range of commits, instead of just one commit, |
| 272 | using range notation. For example: |
Christian Couder | 5413812 | 2008-12-02 14:53:51 +0100 | [diff] [blame] | 273 | |
| 274 | ------------ |
| 275 | $ git bisect skip v2.5..v2.6 |
| 276 | ------------ |
| 277 | |
David J. Mellor | 19fa5e8 | 2009-03-25 20:44:44 -0700 | [diff] [blame] | 278 | This tells the bisect process that no commit after `v2.5`, up to and |
| 279 | including `v2.6`, should be tested. |
Christian Couder | 5413812 | 2008-12-02 14:53:51 +0100 | [diff] [blame] | 280 | |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 281 | Note that if you also want to skip the first commit of the range you |
| 282 | would issue the command: |
Christian Couder | 5413812 | 2008-12-02 14:53:51 +0100 | [diff] [blame] | 283 | |
| 284 | ------------ |
| 285 | $ git bisect skip v2.5 v2.5..v2.6 |
| 286 | ------------ |
| 287 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 288 | This tells the bisect process that the commits between `v2.5` and |
| 289 | `v2.6` (inclusive) should be skipped. |
David J. Mellor | 4306bcb | 2009-03-19 20:35:34 -0700 | [diff] [blame] | 290 | |
Christian Couder | 5413812 | 2008-12-02 14:53:51 +0100 | [diff] [blame] | 291 | |
Christian Couder | 6fe9c57 | 2007-04-05 05:33:53 +0200 | [diff] [blame] | 292 | Cutting down bisection by giving more parameters to bisect start |
| 293 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Christian Couder | 1207f9e | 2007-03-24 06:30:33 +0100 | [diff] [blame] | 294 | |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 295 | You can further cut down the number of trials, if you know what part of |
| 296 | the tree is involved in the problem you are tracking down, by specifying |
David J. Mellor | 4306bcb | 2009-03-19 20:35:34 -0700 | [diff] [blame] | 297 | path parameters when issuing the `bisect start` command: |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 298 | |
| 299 | ------------ |
Christian Couder | 6fe9c57 | 2007-04-05 05:33:53 +0200 | [diff] [blame] | 300 | $ git bisect start -- arch/i386 include/asm-i386 |
| 301 | ------------ |
| 302 | |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 303 | If you know beforehand more than one good commit, you can narrow the |
| 304 | bisect space down by specifying all of the good commits immediately after |
| 305 | the bad commit when issuing the `bisect start` command: |
Christian Couder | 6fe9c57 | 2007-04-05 05:33:53 +0200 | [diff] [blame] | 306 | |
| 307 | ------------ |
| 308 | $ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 -- |
| 309 | # v2.6.20-rc6 is bad |
| 310 | # v2.6.20-rc4 and v2.6.20-rc1 are good |
Junio C Hamano | 556cb4e | 2005-12-05 00:15:24 -0800 | [diff] [blame] | 311 | ------------ |
| 312 | |
Christian Couder | 1207f9e | 2007-03-24 06:30:33 +0100 | [diff] [blame] | 313 | Bisect run |
| 314 | ~~~~~~~~~~ |
| 315 | |
Christian Couder | 7891a28 | 2007-03-24 06:29:58 +0100 | [diff] [blame] | 316 | If you have a script that can tell if the current source code is good |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 317 | or bad, you can bisect by issuing the command: |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 318 | |
| 319 | ------------ |
John Tapsell | fad5c96 | 2009-03-05 12:36:14 +0000 | [diff] [blame] | 320 | $ git bisect run my_script arguments |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 321 | ------------ |
| 322 | |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 323 | Note that the script (`my_script` in the above example) should exit |
| 324 | with code 0 if the current source code is good/old, and exit with a |
| 325 | code between 1 and 127 (inclusive), except 125, if the current source |
| 326 | code is bad/new. |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 327 | |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 328 | Any other exit code will abort the bisect process. It should be noted |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 329 | that a program that terminates via `exit(-1)` leaves $? = 255, (see the |
| 330 | exit(3) manual page), as the value is chopped with `& 0377`. |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 331 | |
Christian Couder | 71b0251 | 2007-10-26 05:39:37 +0200 | [diff] [blame] | 332 | The special exit code 125 should be used when the current source code |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 333 | cannot be tested. If the script exits with this code, the current |
Junio C Hamano | 958bf6b | 2011-03-19 21:46:06 -0700 | [diff] [blame] | 334 | revision will be skipped (see `git bisect skip` above). 125 was chosen |
| 335 | as the highest sensible value to use for this purpose, because 126 and 127 |
| 336 | are used by POSIX shells to signal specific error status (127 is for |
Junio C Hamano | 3b19dba | 2015-10-22 13:02:33 -0700 | [diff] [blame] | 337 | command not found, 126 is for command found but not executable--these |
Junio C Hamano | 958bf6b | 2011-03-19 21:46:06 -0700 | [diff] [blame] | 338 | details do not matter, as they are normal errors in the script, as far as |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 339 | `bisect run` is concerned). |
Christian Couder | 71b0251 | 2007-10-26 05:39:37 +0200 | [diff] [blame] | 340 | |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 341 | You may often find that during a bisect session you want to have |
| 342 | temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a |
| 343 | header file, or "revision that does not have this commit needs this |
| 344 | patch applied to work around another problem this bisection is not |
| 345 | interested in") applied to the revision being tested. |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 346 | |
Christian Couder | 5bcce84 | 2008-11-09 14:53:14 +0100 | [diff] [blame] | 347 | To cope with such a situation, after the inner 'git bisect' finds the |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 348 | next revision to test, the script can apply the patch |
| 349 | before compiling, run the real test, and afterwards decide if the |
| 350 | revision (possibly with the needed patch) passed the test and then |
| 351 | rewind the tree to the pristine state. Finally the script should exit |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 352 | with the status of the real test to let the `git bisect run` command loop |
David J. Mellor | ee9cf14 | 2009-03-19 00:00:12 -0700 | [diff] [blame] | 353 | determine the eventual outcome of the bisect session. |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 354 | |
Jon Seymour | 88d7891 | 2011-08-04 22:01:03 +1000 | [diff] [blame] | 355 | OPTIONS |
| 356 | ------- |
| 357 | --no-checkout:: |
| 358 | + |
| 359 | Do not checkout the new working tree at each iteration of the bisection |
Matthieu Moy | 661c3e9 | 2016-06-28 13:40:15 +0200 | [diff] [blame] | 360 | process. Instead just update a special reference named `BISECT_HEAD` to make |
Jon Seymour | 88d7891 | 2011-08-04 22:01:03 +1000 | [diff] [blame] | 361 | it point to the commit that should be tested. |
| 362 | + |
| 363 | This option may be useful when the test you would perform in each step |
| 364 | does not require a checked out tree. |
Jon Seymour | 24c5128 | 2011-08-09 12:11:54 +1000 | [diff] [blame] | 365 | + |
| 366 | If the repository is bare, `--no-checkout` is assumed. |
Jon Seymour | 88d7891 | 2011-08-04 22:01:03 +1000 | [diff] [blame] | 367 | |
Christian Couder | bac59f1 | 2008-05-08 01:00:54 +0200 | [diff] [blame] | 368 | EXAMPLES |
| 369 | -------- |
| 370 | |
| 371 | * Automatically bisect a broken build between v1.2 and HEAD: |
| 372 | + |
| 373 | ------------ |
| 374 | $ git bisect start HEAD v1.2 -- # HEAD is bad, v1.2 is good |
| 375 | $ git bisect run make # "make" builds the app |
Michael J Gruber | c787a45 | 2013-02-11 09:35:04 +0100 | [diff] [blame] | 376 | $ git bisect reset # quit the bisect session |
Christian Couder | bac59f1 | 2008-05-08 01:00:54 +0200 | [diff] [blame] | 377 | ------------ |
| 378 | |
John Tapsell | fad5c96 | 2009-03-05 12:36:14 +0000 | [diff] [blame] | 379 | * Automatically bisect a test failure between origin and HEAD: |
| 380 | + |
| 381 | ------------ |
| 382 | $ git bisect start HEAD origin -- # HEAD is bad, origin is good |
| 383 | $ git bisect run make test # "make test" builds and tests |
Michael J Gruber | c787a45 | 2013-02-11 09:35:04 +0100 | [diff] [blame] | 384 | $ git bisect reset # quit the bisect session |
John Tapsell | fad5c96 | 2009-03-05 12:36:14 +0000 | [diff] [blame] | 385 | ------------ |
| 386 | |
Christian Couder | bac59f1 | 2008-05-08 01:00:54 +0200 | [diff] [blame] | 387 | * Automatically bisect a broken test case: |
| 388 | + |
| 389 | ------------ |
| 390 | $ cat ~/test.sh |
| 391 | #!/bin/sh |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 392 | make || exit 125 # this skips broken builds |
Michael J Gruber | 9d79b7e | 2011-03-15 22:24:55 +0100 | [diff] [blame] | 393 | ~/check_test_case.sh # does the test case pass? |
Christian Couder | bac59f1 | 2008-05-08 01:00:54 +0200 | [diff] [blame] | 394 | $ git bisect start HEAD HEAD~10 -- # culprit is among the last 10 |
| 395 | $ git bisect run ~/test.sh |
Michael J Gruber | c787a45 | 2013-02-11 09:35:04 +0100 | [diff] [blame] | 396 | $ git bisect reset # quit the bisect session |
Christian Couder | bac59f1 | 2008-05-08 01:00:54 +0200 | [diff] [blame] | 397 | ------------ |
| 398 | + |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 399 | Here we use a `test.sh` custom script. In this script, if `make` |
Michael J Gruber | 9d79b7e | 2011-03-15 22:24:55 +0100 | [diff] [blame] | 400 | fails, we skip the current commit. |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 401 | `check_test_case.sh` should `exit 0` if the test case passes, |
| 402 | and `exit 1` otherwise. |
Christian Couder | bac59f1 | 2008-05-08 01:00:54 +0200 | [diff] [blame] | 403 | + |
Michael Haggerty | 2df5a84 | 2015-06-26 22:22:46 +0200 | [diff] [blame] | 404 | It is safer if both `test.sh` and `check_test_case.sh` are |
David J. Mellor | 2364259 | 2009-03-16 23:16:15 -0700 | [diff] [blame] | 405 | outside the repository to prevent interactions between the bisect, |
| 406 | make and test processes and the scripts. |
Christian Couder | bac59f1 | 2008-05-08 01:00:54 +0200 | [diff] [blame] | 407 | |
Michael J Gruber | e235b91 | 2011-03-15 22:24:56 +0100 | [diff] [blame] | 408 | * Automatically bisect with temporary modifications (hot-fix): |
| 409 | + |
| 410 | ------------ |
| 411 | $ cat ~/test.sh |
| 412 | #!/bin/sh |
| 413 | |
| 414 | # tweak the working tree by merging the hot-fix branch |
| 415 | # and then attempt a build |
| 416 | if git merge --no-commit hot-fix && |
| 417 | make |
| 418 | then |
| 419 | # run project specific test and report its status |
| 420 | ~/check_test_case.sh |
| 421 | status=$? |
| 422 | else |
| 423 | # tell the caller this is untestable |
| 424 | status=125 |
| 425 | fi |
| 426 | |
| 427 | # undo the tweak to allow clean flipping to the next commit |
| 428 | git reset --hard |
| 429 | |
| 430 | # return control |
| 431 | exit $status |
| 432 | ------------ |
| 433 | + |
| 434 | This applies modifications from a hot-fix branch before each test run, |
| 435 | e.g. in case your build or test environment changed so that older |
| 436 | revisions may need a fix which newer ones have already. (Make sure the |
| 437 | hot-fix branch is based off a commit which is contained in all revisions |
| 438 | which you are bisecting, so that the merge does not pull in too much, or |
| 439 | use `git cherry-pick` instead of `git merge`.) |
| 440 | |
Michael J Gruber | 9d79b7e | 2011-03-15 22:24:55 +0100 | [diff] [blame] | 441 | * Automatically bisect a broken test case: |
John Tapsell | fad5c96 | 2009-03-05 12:36:14 +0000 | [diff] [blame] | 442 | + |
| 443 | ------------ |
| 444 | $ git bisect start HEAD HEAD~10 -- # culprit is among the last 10 |
| 445 | $ git bisect run sh -c "make || exit 125; ~/check_test_case.sh" |
Michael J Gruber | c787a45 | 2013-02-11 09:35:04 +0100 | [diff] [blame] | 446 | $ git bisect reset # quit the bisect session |
John Tapsell | fad5c96 | 2009-03-05 12:36:14 +0000 | [diff] [blame] | 447 | ------------ |
| 448 | + |
Michael J Gruber | 9d79b7e | 2011-03-15 22:24:55 +0100 | [diff] [blame] | 449 | This shows that you can do without a run script if you write the test |
| 450 | on a single line. |
John Tapsell | fad5c96 | 2009-03-05 12:36:14 +0000 | [diff] [blame] | 451 | |
Jon Seymour | 88d7891 | 2011-08-04 22:01:03 +1000 | [diff] [blame] | 452 | * Locate a good region of the object graph in a damaged repository |
| 453 | + |
| 454 | ------------ |
| 455 | $ git bisect start HEAD <known-good-commit> [ <boundary-commit> ... ] --no-checkout |
| 456 | $ git bisect run sh -c ' |
| 457 | GOOD=$(git for-each-ref "--format=%(objectname)" refs/bisect/good-*) && |
| 458 | git rev-list --objects BISECT_HEAD --not $GOOD >tmp.$$ && |
| 459 | git pack-objects --stdout >/dev/null <tmp.$$ |
| 460 | rc=$? |
| 461 | rm -f tmp.$$ |
| 462 | test $rc = 0' |
| 463 | |
Michael J Gruber | c787a45 | 2013-02-11 09:35:04 +0100 | [diff] [blame] | 464 | $ git bisect reset # quit the bisect session |
Jon Seymour | 88d7891 | 2011-08-04 22:01:03 +1000 | [diff] [blame] | 465 | ------------ |
| 466 | + |
| 467 | In this case, when 'git bisect run' finishes, bisect/bad will refer to a commit that |
| 468 | has at least one parent whose reachable graph is fully traversable in the sense |
| 469 | required by 'git pack objects'. |
| 470 | |
Antoine Delaite | 21e5cfd | 2015-06-29 17:40:33 +0200 | [diff] [blame] | 471 | * Look for a fix instead of a regression in the code |
| 472 | + |
| 473 | ------------ |
| 474 | $ git bisect start |
| 475 | $ git bisect new HEAD # current commit is marked as new |
| 476 | $ git bisect old HEAD~10 # the tenth commit from now is marked as old |
| 477 | ------------ |
Matthieu Moy | 06e6a74 | 2015-06-29 17:40:35 +0200 | [diff] [blame] | 478 | + |
| 479 | or: |
| 480 | ------------ |
| 481 | $ git bisect start --term-old broken --term-new fixed |
| 482 | $ git bisect fixed |
| 483 | $ git bisect broken HEAD~10 |
| 484 | ------------ |
Antoine Delaite | 21e5cfd | 2015-06-29 17:40:33 +0200 | [diff] [blame] | 485 | |
Matthieu Moy | c949397 | 2015-06-26 18:58:11 +0200 | [diff] [blame] | 486 | Getting help |
| 487 | ~~~~~~~~~~~~ |
| 488 | |
| 489 | Use `git bisect` to get a short usage description, and `git bisect |
| 490 | help` or `git bisect -h` to get a long usage description. |
Jon Seymour | 88d7891 | 2011-08-04 22:01:03 +1000 | [diff] [blame] | 491 | |
Christian Couder | 69a9cd3 | 2009-11-08 16:09:47 +0100 | [diff] [blame] | 492 | SEE ALSO |
| 493 | -------- |
| 494 | link:git-bisect-lk2009.html[Fighting regressions with git bisect], |
| 495 | linkgit:git-blame[1]. |
| 496 | |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 497 | GIT |
| 498 | --- |
Christian Couder | 9e1f0a8 | 2008-06-06 09:07:32 +0200 | [diff] [blame] | 499 | Part of the linkgit:git[1] suite |