Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
| 2 | "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 6 | <meta name="generator" content="AsciiDoc 8.2.5" /> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | <style type="text/css"> |
| 8 | /* Debug borders */ |
| 9 | p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 { |
| 10 | /* |
| 11 | border: 1px solid red; |
| 12 | */ |
| 13 | } |
| 14 | |
| 15 | body { |
| 16 | margin: 1em 5% 1em 5%; |
| 17 | } |
| 18 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 19 | a { |
| 20 | color: blue; |
| 21 | text-decoration: underline; |
| 22 | } |
| 23 | a:visited { |
| 24 | color: fuchsia; |
| 25 | } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 26 | |
| 27 | em { |
| 28 | font-style: italic; |
| 29 | } |
| 30 | |
| 31 | strong { |
| 32 | font-weight: bold; |
| 33 | } |
| 34 | |
| 35 | tt { |
| 36 | color: navy; |
| 37 | } |
| 38 | |
| 39 | h1, h2, h3, h4, h5, h6 { |
| 40 | color: #527bbd; |
| 41 | font-family: sans-serif; |
| 42 | margin-top: 1.2em; |
| 43 | margin-bottom: 0.5em; |
| 44 | line-height: 1.3; |
| 45 | } |
| 46 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 47 | h1, h2, h3 { |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 48 | border-bottom: 2px solid silver; |
| 49 | } |
| 50 | h2 { |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 51 | padding-top: 0.5em; |
| 52 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 53 | h3 { |
| 54 | float: left; |
| 55 | } |
| 56 | h3 + * { |
| 57 | clear: left; |
| 58 | } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 59 | |
| 60 | div.sectionbody { |
| 61 | font-family: serif; |
| 62 | margin-left: 0; |
| 63 | } |
| 64 | |
| 65 | hr { |
| 66 | border: 1px solid silver; |
| 67 | } |
| 68 | |
| 69 | p { |
| 70 | margin-top: 0.5em; |
| 71 | margin-bottom: 0.5em; |
| 72 | } |
| 73 | |
| 74 | pre { |
| 75 | padding: 0; |
| 76 | margin: 0; |
| 77 | } |
| 78 | |
| 79 | span#author { |
| 80 | color: #527bbd; |
| 81 | font-family: sans-serif; |
| 82 | font-weight: bold; |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 83 | font-size: 1.1em; |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 84 | } |
| 85 | span#email { |
| 86 | } |
| 87 | span#revision { |
| 88 | font-family: sans-serif; |
| 89 | } |
| 90 | |
| 91 | div#footer { |
| 92 | font-family: sans-serif; |
| 93 | font-size: small; |
| 94 | border-top: 2px solid silver; |
| 95 | padding-top: 0.5em; |
| 96 | margin-top: 4.0em; |
| 97 | } |
| 98 | div#footer-text { |
| 99 | float: left; |
| 100 | padding-bottom: 0.5em; |
| 101 | } |
| 102 | div#footer-badges { |
| 103 | float: right; |
| 104 | padding-bottom: 0.5em; |
| 105 | } |
| 106 | |
| 107 | div#preamble, |
| 108 | div.tableblock, div.imageblock, div.exampleblock, div.verseblock, |
| 109 | div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock, |
| 110 | div.admonitionblock { |
| 111 | margin-right: 10%; |
| 112 | margin-top: 1.5em; |
| 113 | margin-bottom: 1.5em; |
| 114 | } |
| 115 | div.admonitionblock { |
| 116 | margin-top: 2.5em; |
| 117 | margin-bottom: 2.5em; |
| 118 | } |
| 119 | |
| 120 | div.content { /* Block element content. */ |
| 121 | padding: 0; |
| 122 | } |
| 123 | |
| 124 | /* Block element titles. */ |
| 125 | div.title, caption.title { |
| 126 | font-family: sans-serif; |
| 127 | font-weight: bold; |
| 128 | text-align: left; |
| 129 | margin-top: 1.0em; |
| 130 | margin-bottom: 0.5em; |
| 131 | } |
| 132 | div.title + * { |
| 133 | margin-top: 0; |
| 134 | } |
| 135 | |
| 136 | td div.title:first-child { |
| 137 | margin-top: 0.0em; |
| 138 | } |
| 139 | div.content div.title:first-child { |
| 140 | margin-top: 0.0em; |
| 141 | } |
| 142 | div.content + div.title { |
| 143 | margin-top: 0.0em; |
| 144 | } |
| 145 | |
| 146 | div.sidebarblock > div.content { |
| 147 | background: #ffffee; |
| 148 | border: 1px solid silver; |
| 149 | padding: 0.5em; |
| 150 | } |
| 151 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 152 | div.listingblock { |
| 153 | margin-right: 0%; |
| 154 | } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 155 | div.listingblock > div.content { |
| 156 | border: 1px solid silver; |
| 157 | background: #f4f4f4; |
| 158 | padding: 0.5em; |
| 159 | } |
| 160 | |
| 161 | div.quoteblock > div.content { |
| 162 | padding-left: 2.0em; |
| 163 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 164 | |
| 165 | div.attribution { |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 166 | text-align: right; |
| 167 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 168 | div.verseblock + div.attribution { |
| 169 | text-align: left; |
| 170 | } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 171 | |
| 172 | div.admonitionblock .icon { |
| 173 | vertical-align: top; |
| 174 | font-size: 1.1em; |
| 175 | font-weight: bold; |
| 176 | text-decoration: underline; |
| 177 | color: #527bbd; |
| 178 | padding-right: 0.5em; |
| 179 | } |
| 180 | div.admonitionblock td.content { |
| 181 | padding-left: 0.5em; |
| 182 | border-left: 2px solid silver; |
| 183 | } |
| 184 | |
| 185 | div.exampleblock > div.content { |
| 186 | border-left: 2px solid silver; |
| 187 | padding: 0.5em; |
| 188 | } |
| 189 | |
| 190 | div.verseblock div.content { |
| 191 | white-space: pre; |
| 192 | } |
| 193 | |
| 194 | div.imageblock div.content { padding-left: 0; } |
| 195 | div.imageblock img { border: 1px solid silver; } |
| 196 | span.image img { border-style: none; } |
| 197 | |
| 198 | dl { |
| 199 | margin-top: 0.8em; |
| 200 | margin-bottom: 0.8em; |
| 201 | } |
| 202 | dt { |
| 203 | margin-top: 0.5em; |
| 204 | margin-bottom: 0; |
| 205 | font-style: italic; |
| 206 | } |
| 207 | dd > *:first-child { |
| 208 | margin-top: 0; |
| 209 | } |
| 210 | |
| 211 | ul, ol { |
| 212 | list-style-position: outside; |
| 213 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 214 | div.olist2 ol { |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 215 | list-style-type: lower-alpha; |
| 216 | } |
| 217 | |
| 218 | div.tableblock > table { |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 219 | border: 3px solid #527bbd; |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 220 | } |
| 221 | thead { |
| 222 | font-family: sans-serif; |
| 223 | font-weight: bold; |
| 224 | } |
| 225 | tfoot { |
| 226 | font-weight: bold; |
| 227 | } |
| 228 | |
| 229 | div.hlist { |
| 230 | margin-top: 0.8em; |
| 231 | margin-bottom: 0.8em; |
| 232 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 233 | div.hlist td { |
| 234 | padding-bottom: 5px; |
| 235 | } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 236 | td.hlist1 { |
| 237 | vertical-align: top; |
| 238 | font-style: italic; |
| 239 | padding-right: 0.8em; |
| 240 | } |
| 241 | td.hlist2 { |
| 242 | vertical-align: top; |
| 243 | } |
| 244 | |
| 245 | @media print { |
| 246 | div#footer-badges { display: none; } |
| 247 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 248 | |
| 249 | div#toctitle { |
| 250 | color: #527bbd; |
| 251 | font-family: sans-serif; |
| 252 | font-size: 1.1em; |
| 253 | font-weight: bold; |
| 254 | margin-top: 1.0em; |
| 255 | margin-bottom: 0.1em; |
| 256 | } |
| 257 | |
| 258 | div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 { |
| 259 | margin-top: 0; |
| 260 | margin-bottom: 0; |
| 261 | } |
| 262 | div.toclevel2 { |
| 263 | margin-left: 2em; |
| 264 | font-size: 0.9em; |
| 265 | } |
| 266 | div.toclevel3 { |
| 267 | margin-left: 4em; |
| 268 | font-size: 0.9em; |
| 269 | } |
| 270 | div.toclevel4 { |
| 271 | margin-left: 6em; |
| 272 | font-size: 0.9em; |
| 273 | } |
| 274 | include1::./stylesheets/xhtml11-manpage.css[] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 275 | /* Workarounds for IE6's broken and incomplete CSS2. */ |
| 276 | |
| 277 | div.sidebar-content { |
| 278 | background: #ffffee; |
| 279 | border: 1px solid silver; |
| 280 | padding: 0.5em; |
| 281 | } |
| 282 | div.sidebar-title, div.image-title { |
| 283 | font-family: sans-serif; |
| 284 | font-weight: bold; |
| 285 | margin-top: 0.0em; |
| 286 | margin-bottom: 0.5em; |
| 287 | } |
| 288 | |
| 289 | div.listingblock div.content { |
| 290 | border: 1px solid silver; |
| 291 | background: #f4f4f4; |
| 292 | padding: 0.5em; |
| 293 | } |
| 294 | |
| 295 | div.quoteblock-content { |
| 296 | padding-left: 2.0em; |
| 297 | } |
| 298 | |
| 299 | div.exampleblock-content { |
| 300 | border-left: 2px solid silver; |
| 301 | padding-left: 0.5em; |
| 302 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 303 | |
| 304 | /* IE6 sets dynamically generated links as visited. */ |
| 305 | div#toc a:visited { color: blue; } |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 306 | </style> |
| 307 | <title>git-rebase(1)</title> |
| 308 | </head> |
| 309 | <body> |
| 310 | <div id="header"> |
| 311 | <h1> |
| 312 | git-rebase(1) Manual Page |
| 313 | </h1> |
| 314 | <h2>NAME</h2> |
| 315 | <div class="sectionbody"> |
| 316 | <p>git-rebase - |
Junio C Hamano | 7c73c66 | 2007-01-19 00:37:50 | [diff] [blame] | 317 | Forward-port local commits to the updated upstream head |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 318 | </p> |
| 319 | </div> |
| 320 | </div> |
| 321 | <h2>SYNOPSIS</h2> |
| 322 | <div class="sectionbody"> |
Junio C Hamano | a9b8d24 | 2007-05-19 04:51:55 | [diff] [blame] | 323 | <div class="verseblock"> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 324 | <div class="content"><em>git rebase</em> [-i | --interactive] [-v | --verbose] [-m | --merge] |
Junio C Hamano | 4f1d8c4 | 2008-03-03 02:01:16 | [diff] [blame] | 325 | [-s <strategy> | --strategy=<strategy>] |
Junio C Hamano | 250f03e | 2007-09-10 01:33:28 | [diff] [blame] | 326 | [-C<n>] [ --whitespace=<option>] [-p | --preserve-merges] |
| 327 | [--onto <newbase>] <upstream> [<branch>] |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 328 | <em>git rebase</em> --continue | --skip | --abort</div></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 329 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 330 | <h2 id="_description">DESCRIPTION</h2> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 331 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 332 | <div class="para"><p>If <branch> is specified, <em>git-rebase</em> will perform an automatic |
Junio C Hamano | 89d4e0f | 2007-02-18 00:34:59 | [diff] [blame] | 333 | <tt>git checkout <branch></tt> before doing anything else. Otherwise |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 334 | it remains on the current branch.</p></div> |
| 335 | <div class="para"><p>All changes made by commits in the current branch but that are not |
Junio C Hamano | 89d4e0f | 2007-02-18 00:34:59 | [diff] [blame] | 336 | in <upstream> are saved to a temporary area. This is the same set |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 337 | of commits that would be shown by <tt>git log <upstream>..HEAD</tt>.</p></div> |
| 338 | <div class="para"><p>The current branch is reset to <upstream>, or <newbase> if the |
Junio C Hamano | 89d4e0f | 2007-02-18 00:34:59 | [diff] [blame] | 339 | --onto option was supplied. This has the exact same effect as |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 340 | <tt>git reset --hard <upstream></tt> (or <newbase>). ORIG_HEAD is set |
| 341 | to point at the tip of the branch before the reset.</p></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 342 | <div class="para"><p>The commits that were previously saved into the temporary area are |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 343 | then reapplied to the current branch, one by one, in order. Note that |
| 344 | any commits in HEAD which introduce the same textual changes as a commit |
| 345 | in HEAD..<upstream> are omitted (i.e., a patch already accepted upstream |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 346 | with a different commit message or timestamp will be skipped).</p></div> |
| 347 | <div class="para"><p>It is possible that a merge failure will prevent this process from being |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 348 | completely automatic. You will have to resolve any such merge failure |
Junio C Hamano | 6959c6c | 2006-05-17 10:34:11 | [diff] [blame] | 349 | and run <tt>git rebase --continue</tt>. Another option is to bypass the commit |
| 350 | that caused the merge failure with <tt>git rebase --skip</tt>. To restore the |
Junio C Hamano | 0868a30 | 2008-07-22 09:20:44 | [diff] [blame] | 351 | original <branch> and remove the .git/rebase-apply working files, use the |
| 352 | command <tt>git rebase --abort</tt> instead.</p></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 353 | <div class="para"><p>Assume the following history exists and the current branch is "topic":</p></div> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 354 | <div class="listingblock"> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 355 | <div class="content"> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 356 | <pre><tt> A---B---C topic |
| 357 | / |
| 358 | D---E---F---G master</tt></pre> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 359 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 360 | <div class="para"><p>From this point, the result of either of the following commands:</p></div> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 361 | <div class="literalblock"> |
| 362 | <div class="content"> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 363 | <pre><tt>git rebase master |
| 364 | git rebase master topic</tt></pre> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 365 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 366 | <div class="para"><p>would be:</p></div> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 367 | <div class="listingblock"> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 368 | <div class="content"> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 369 | <pre><tt> A'--B'--C' topic |
| 370 | / |
| 371 | D---E---F---G master</tt></pre> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 372 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 373 | <div class="para"><p>The latter form is just a short-hand of <tt>git checkout topic</tt> |
| 374 | followed by <tt>git rebase master</tt>.</p></div> |
| 375 | <div class="para"><p>If the upstream branch already contains a change you have made (e.g., |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 376 | because you mailed a patch which was applied upstream), then that commit |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 377 | will be skipped. For example, running <tt>git rebase master</tt> on the |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 378 | following history (in which A' and A introduce the same set of changes, |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 379 | but have different committer information):</p></div> |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 380 | <div class="listingblock"> |
| 381 | <div class="content"> |
| 382 | <pre><tt> A---B---C topic |
| 383 | / |
| 384 | D---E---A'---F master</tt></pre> |
| 385 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 386 | <div class="para"><p>will result in:</p></div> |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 387 | <div class="listingblock"> |
| 388 | <div class="content"> |
| 389 | <pre><tt> B'---C' topic |
| 390 | / |
| 391 | D---E---A'---F master</tt></pre> |
| 392 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 393 | <div class="para"><p>Here is how you would transplant a topic branch based on one |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 394 | branch to another, to pretend that you forked the topic branch |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 395 | from the latter branch, using <tt>rebase --onto</tt>.</p></div> |
| 396 | <div class="para"><p>First let's assume your <em>topic</em> is based on branch <em>next</em>. |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 397 | For example feature developed in <em>topic</em> depends on some |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 398 | functionality which is found in <em>next</em>.</p></div> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 399 | <div class="listingblock"> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 400 | <div class="content"> |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 401 | <pre><tt> o---o---o---o---o master |
| 402 | \ |
| 403 | o---o---o---o---o next |
| 404 | \ |
| 405 | o---o---o topic</tt></pre> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 406 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 407 | <div class="para"><p>We would want to make <em>topic</em> forked from branch <em>master</em>, |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 408 | for example because the functionality <em>topic</em> branch depend on |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 409 | got merged into more stable <em>master</em> branch, like this:</p></div> |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 410 | <div class="listingblock"> |
| 411 | <div class="content"> |
| 412 | <pre><tt> o---o---o---o---o master |
| 413 | | \ |
| 414 | | o'--o'--o' topic |
| 415 | \ |
| 416 | o---o---o---o---o next</tt></pre> |
| 417 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 418 | <div class="para"><p>We can get this using the following command:</p></div> |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 419 | <div class="literalblock"> |
| 420 | <div class="content"> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 421 | <pre><tt>git rebase --onto master next topic</tt></pre> |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 422 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 423 | <div class="para"><p>Another example of --onto option is to rebase part of a |
| 424 | branch. If we have the following situation:</p></div> |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 425 | <div class="listingblock"> |
| 426 | <div class="content"> |
| 427 | <pre><tt> H---I---J topicB |
| 428 | / |
| 429 | E---F---G topicA |
| 430 | / |
| 431 | A---B---C---D master</tt></pre> |
| 432 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 433 | <div class="para"><p>then the command</p></div> |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 434 | <div class="literalblock"> |
| 435 | <div class="content"> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 436 | <pre><tt>git rebase --onto master topicA topicB</tt></pre> |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 437 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 438 | <div class="para"><p>would result in:</p></div> |
Junio C Hamano | d8c9d43 | 2006-11-07 07:19:13 | [diff] [blame] | 439 | <div class="listingblock"> |
| 440 | <div class="content"> |
| 441 | <pre><tt> H'--I'--J' topicB |
| 442 | / |
| 443 | | E---F---G topicA |
| 444 | |/ |
| 445 | A---B---C---D master</tt></pre> |
| 446 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 447 | <div class="para"><p>This is useful when topicB does not depend on topicA.</p></div> |
| 448 | <div class="para"><p>A range of commits could also be removed with rebase. If we have |
| 449 | the following situation:</p></div> |
Junio C Hamano | 42f855f | 2007-02-06 00:09:38 | [diff] [blame] | 450 | <div class="listingblock"> |
| 451 | <div class="content"> |
| 452 | <pre><tt> E---F---G---H---I---J topicA</tt></pre> |
| 453 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 454 | <div class="para"><p>then the command</p></div> |
Junio C Hamano | 42f855f | 2007-02-06 00:09:38 | [diff] [blame] | 455 | <div class="literalblock"> |
| 456 | <div class="content"> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 457 | <pre><tt>git rebase --onto topicA~5 topicA~3 topicA</tt></pre> |
Junio C Hamano | 42f855f | 2007-02-06 00:09:38 | [diff] [blame] | 458 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 459 | <div class="para"><p>would result in the removal of commits F and G:</p></div> |
Junio C Hamano | 42f855f | 2007-02-06 00:09:38 | [diff] [blame] | 460 | <div class="listingblock"> |
| 461 | <div class="content"> |
| 462 | <pre><tt> E---H'---I'---J' topicA</tt></pre> |
| 463 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 464 | <div class="para"><p>This is useful if F and G were flawed in some way, or should not be |
Junio C Hamano | 42f855f | 2007-02-06 00:09:38 | [diff] [blame] | 465 | part of topicA. Note that the argument to --onto and the <upstream> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 466 | parameter can be any valid commit-ish.</p></div> |
| 467 | <div class="para"><p>In case of conflict, <em>git-rebase</em> will stop at the first problematic commit |
| 468 | and leave conflict markers in the tree. You can use <em>git-diff</em> to locate |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 469 | the markers (<<<<<<) and make edits to resolve the conflict. For each |
| 470 | file you edit, you need to tell git that the conflict has been resolved, |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 471 | typically this would be done with</p></div> |
Junio C Hamano | f02e09f | 2006-03-27 07:51:03 | [diff] [blame] | 472 | <div class="literalblock"> |
| 473 | <div class="content"> |
Junio C Hamano | 89d4e0f | 2007-02-18 00:34:59 | [diff] [blame] | 474 | <pre><tt>git add <filename></tt></pre> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 475 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 476 | <div class="para"><p>After resolving the conflict manually and updating the index with the |
| 477 | desired resolution, you can continue the rebasing process with</p></div> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 478 | <div class="literalblock"> |
| 479 | <div class="content"> |
| 480 | <pre><tt>git rebase --continue</tt></pre> |
Junio C Hamano | f02e09f | 2006-03-27 07:51:03 | [diff] [blame] | 481 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 482 | <div class="para"><p>Alternatively, you can undo the <em>git-rebase</em> with</p></div> |
Junio C Hamano | f02e09f | 2006-03-27 07:51:03 | [diff] [blame] | 483 | <div class="literalblock"> |
| 484 | <div class="content"> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 485 | <pre><tt>git rebase --abort</tt></pre> |
Junio C Hamano | f02e09f | 2006-03-27 07:51:03 | [diff] [blame] | 486 | </div></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 487 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 488 | <h2 id="_options">OPTIONS</h2> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 489 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 490 | <div class="vlist"><dl> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 491 | <dt> |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 492 | <newbase> |
| 493 | </dt> |
| 494 | <dd> |
| 495 | <p> |
| 496 | Starting point at which to create the new commits. If the |
| 497 | --onto option is not specified, the starting point is |
Junio C Hamano | 42f855f | 2007-02-06 00:09:38 | [diff] [blame] | 498 | <upstream>. May be any valid commit, and not just an |
| 499 | existing branch name. |
Junio C Hamano | 7e9f6b7 | 2006-02-22 10:44:55 | [diff] [blame] | 500 | </p> |
| 501 | </dd> |
| 502 | <dt> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 503 | <upstream> |
| 504 | </dt> |
| 505 | <dd> |
| 506 | <p> |
Junio C Hamano | 42f855f | 2007-02-06 00:09:38 | [diff] [blame] | 507 | Upstream branch to compare against. May be any valid commit, |
| 508 | not just an existing branch name. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 509 | </p> |
| 510 | </dd> |
| 511 | <dt> |
Junio C Hamano | 2b13527 | 2006-03-18 07:45:42 | [diff] [blame] | 512 | <branch> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 513 | </dt> |
| 514 | <dd> |
| 515 | <p> |
| 516 | Working branch; defaults to HEAD. |
| 517 | </p> |
| 518 | </dd> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 519 | <dt> |
| 520 | --continue |
| 521 | </dt> |
| 522 | <dd> |
| 523 | <p> |
| 524 | Restart the rebasing process after having resolved a merge conflict. |
| 525 | </p> |
| 526 | </dd> |
| 527 | <dt> |
| 528 | --abort |
| 529 | </dt> |
| 530 | <dd> |
| 531 | <p> |
| 532 | Restore the original branch and abort the rebase operation. |
| 533 | </p> |
| 534 | </dd> |
Junio C Hamano | 97f518c | 2006-06-22 19:49:35 | [diff] [blame] | 535 | <dt> |
| 536 | --skip |
| 537 | </dt> |
| 538 | <dd> |
| 539 | <p> |
| 540 | Restart the rebasing process by skipping the current patch. |
Junio C Hamano | 97f518c | 2006-06-22 19:49:35 | [diff] [blame] | 541 | </p> |
| 542 | </dd> |
| 543 | <dt> |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 544 | -m |
| 545 | </dt> |
| 546 | <dt> |
| 547 | --merge |
Junio C Hamano | 97f518c | 2006-06-22 19:49:35 | [diff] [blame] | 548 | </dt> |
| 549 | <dd> |
| 550 | <p> |
| 551 | Use merging strategies to rebase. When the recursive (default) merge |
| 552 | strategy is used, this allows rebase to be aware of renames on the |
| 553 | upstream side. |
| 554 | </p> |
| 555 | </dd> |
| 556 | <dt> |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 557 | -s <strategy> |
| 558 | </dt> |
| 559 | <dt> |
| 560 | --strategy=<strategy> |
Junio C Hamano | 97f518c | 2006-06-22 19:49:35 | [diff] [blame] | 561 | </dt> |
| 562 | <dd> |
| 563 | <p> |
| 564 | Use the given merge strategy; can be supplied more than |
| 565 | once to specify them in the order they should be tried. |
| 566 | If there is no <tt>-s</tt> option, a built-in list of strategies |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 567 | is used instead (<em>git-merge-recursive</em> when merging a single |
| 568 | head, <em>git-merge-octopus</em> otherwise). This implies --merge. |
Junio C Hamano | 97f518c | 2006-06-22 19:49:35 | [diff] [blame] | 569 | </p> |
| 570 | </dd> |
Junio C Hamano | fbe0052 | 2006-10-19 05:58:48 | [diff] [blame] | 571 | <dt> |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 572 | -v |
| 573 | </dt> |
| 574 | <dt> |
| 575 | --verbose |
Junio C Hamano | fbe0052 | 2006-10-19 05:58:48 | [diff] [blame] | 576 | </dt> |
| 577 | <dd> |
| 578 | <p> |
| 579 | Display a diffstat of what changed upstream since the last rebase. |
| 580 | </p> |
| 581 | </dd> |
Junio C Hamano | d333998 | 2007-02-09 08:38:48 | [diff] [blame] | 582 | <dt> |
| 583 | -C<n> |
| 584 | </dt> |
| 585 | <dd> |
| 586 | <p> |
| 587 | Ensure at least <n> lines of surrounding context match before |
| 588 | and after each change. When fewer lines of surrounding |
| 589 | context exist they all must match. By default no context is |
| 590 | ever ignored. |
| 591 | </p> |
| 592 | </dd> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 593 | <dt> |
Junio C Hamano | 250f03e | 2007-09-10 01:33:28 | [diff] [blame] | 594 | --whitespace=<nowarn|warn|error|error-all|strip> |
| 595 | </dt> |
| 596 | <dd> |
| 597 | <p> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 598 | This flag is passed to the <em>git-apply</em> program |
Junio C Hamano | 250f03e | 2007-09-10 01:33:28 | [diff] [blame] | 599 | (see <a href="git-apply.html">git-apply(1)</a>) that applies the patch. |
| 600 | </p> |
| 601 | </dd> |
| 602 | <dt> |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 603 | -i |
| 604 | </dt> |
| 605 | <dt> |
| 606 | --interactive |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 607 | </dt> |
| 608 | <dd> |
| 609 | <p> |
| 610 | Make a list of the commits which are about to be rebased. Let the |
Junio C Hamano | dbb6459 | 2007-09-01 11:17:39 | [diff] [blame] | 611 | user edit that list before rebasing. This mode can also be used to |
| 612 | split commits (see SPLITTING COMMITS below). |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 613 | </p> |
| 614 | </dd> |
| 615 | <dt> |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 616 | -p |
| 617 | </dt> |
| 618 | <dt> |
| 619 | --preserve-merges |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 620 | </dt> |
| 621 | <dd> |
| 622 | <p> |
| 623 | Instead of ignoring merges, try to recreate them. This option |
| 624 | only works in interactive mode. |
| 625 | </p> |
| 626 | </dd> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 627 | </dl></div> |
Junio C Hamano | 97f518c | 2006-06-22 19:49:35 | [diff] [blame] | 628 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 629 | <h2 id="_merge_strategies">MERGE STRATEGIES</h2> |
Junio C Hamano | 97f518c | 2006-06-22 19:49:35 | [diff] [blame] | 630 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 631 | <div class="vlist"><dl> |
Junio C Hamano | 97f518c | 2006-06-22 19:49:35 | [diff] [blame] | 632 | <dt> |
| 633 | resolve |
| 634 | </dt> |
| 635 | <dd> |
| 636 | <p> |
| 637 | This can only resolve two heads (i.e. the current branch |
| 638 | and another branch you pulled from) using 3-way merge |
| 639 | algorithm. It tries to carefully detect criss-cross |
| 640 | merge ambiguities and is considered generally safe and |
| 641 | fast. |
| 642 | </p> |
| 643 | </dd> |
| 644 | <dt> |
| 645 | recursive |
| 646 | </dt> |
| 647 | <dd> |
| 648 | <p> |
| 649 | This can only resolve two heads using 3-way merge |
| 650 | algorithm. When there are more than one common |
| 651 | ancestors that can be used for 3-way merge, it creates a |
| 652 | merged tree of the common ancestors and uses that as |
| 653 | the reference tree for the 3-way merge. This has been |
| 654 | reported to result in fewer merge conflicts without |
| 655 | causing mis-merges by tests done on actual merge commits |
| 656 | taken from Linux 2.6 kernel development history. |
| 657 | Additionally this can detect and handle merges involving |
| 658 | renames. This is the default merge strategy when |
| 659 | pulling or merging one branch. |
| 660 | </p> |
| 661 | </dd> |
| 662 | <dt> |
| 663 | octopus |
| 664 | </dt> |
| 665 | <dd> |
| 666 | <p> |
| 667 | This resolves more than two-head case, but refuses to do |
| 668 | complex merge that needs manual resolution. It is |
| 669 | primarily meant to be used for bundling topic branch |
| 670 | heads together. This is the default merge strategy when |
| 671 | pulling or merging more than one branches. |
| 672 | </p> |
| 673 | </dd> |
| 674 | <dt> |
| 675 | ours |
| 676 | </dt> |
| 677 | <dd> |
| 678 | <p> |
| 679 | This resolves any number of heads, but the result of the |
| 680 | merge is always the current branch head. It is meant to |
| 681 | be used to supersede old development history of side |
| 682 | branches. |
| 683 | </p> |
| 684 | </dd> |
Junio C Hamano | e6c9203 | 2008-03-19 09:24:34 | [diff] [blame] | 685 | <dt> |
| 686 | subtree |
| 687 | </dt> |
| 688 | <dd> |
| 689 | <p> |
| 690 | This is a modified recursive strategy. When merging trees A and |
| 691 | B, if B corresponds to a subtree of A, B is first adjusted to |
| 692 | match the tree structure of A, instead of reading the trees at |
| 693 | the same level. This adjustment is also done to the common |
| 694 | ancestor tree. |
| 695 | </p> |
| 696 | </dd> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 697 | </dl></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 698 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 699 | <h2 id="_notes">NOTES</h2> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 700 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 701 | <div class="para"><p>When you rebase a branch, you are changing its history in a way that |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 702 | will cause problems for anyone who already has a copy of the branch |
| 703 | in their repository and tries to pull updates from you. You should |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 704 | understand the implications of using <em>git-rebase</em> on a repository that |
| 705 | you share.</p></div> |
| 706 | <div class="para"><p>When the git-rebase command is run, it will first execute a "pre-rebase" |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 707 | hook if one exists. You can use this hook to do sanity checks and |
| 708 | reject the rebase if it isn't appropriate. Please see the template |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 709 | pre-rebase hook script for an example.</p></div> |
| 710 | <div class="para"><p>Upon completion, <branch> will be the current branch.</p></div> |
Junio C Hamano | 6112cad | 2006-05-02 07:28:06 | [diff] [blame] | 711 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 712 | <h2 id="_interactive_mode">INTERACTIVE MODE</h2> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 713 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 714 | <div class="para"><p>Rebasing interactively means that you have a chance to edit the commits |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 715 | which are rebased. You can reorder the commits, and you can |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 716 | remove them (weeding out bad or otherwise unwanted patches).</p></div> |
| 717 | <div class="para"><p>The interactive mode is meant for this type of workflow:</p></div> |
| 718 | <div class="olist"><ol> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 719 | <li> |
| 720 | <p> |
| 721 | have a wonderful idea |
| 722 | </p> |
| 723 | </li> |
| 724 | <li> |
| 725 | <p> |
| 726 | hack on the code |
| 727 | </p> |
| 728 | </li> |
| 729 | <li> |
| 730 | <p> |
| 731 | prepare a series for submission |
| 732 | </p> |
| 733 | </li> |
| 734 | <li> |
| 735 | <p> |
| 736 | submit |
| 737 | </p> |
| 738 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 739 | </ol></div> |
| 740 | <div class="para"><p>where point 2. consists of several instances of</p></div> |
| 741 | <div class="olist2"><ol> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 742 | <li> |
| 743 | <p> |
| 744 | regular use |
| 745 | </p> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 746 | <div class="olist"><ol> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 747 | <li> |
| 748 | <p> |
| 749 | finish something worthy of a commit |
| 750 | </p> |
| 751 | </li> |
| 752 | <li> |
| 753 | <p> |
| 754 | commit |
| 755 | </p> |
| 756 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 757 | </ol></div> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 758 | </li> |
| 759 | <li> |
| 760 | <p> |
| 761 | independent fixup |
| 762 | </p> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 763 | <div class="olist"><ol> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 764 | <li> |
| 765 | <p> |
| 766 | realize that something does not work |
| 767 | </p> |
| 768 | </li> |
| 769 | <li> |
| 770 | <p> |
| 771 | fix that |
| 772 | </p> |
| 773 | </li> |
| 774 | <li> |
| 775 | <p> |
| 776 | commit it |
| 777 | </p> |
| 778 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 779 | </ol></div> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 780 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 781 | </ol></div> |
| 782 | <div class="para"><p>Sometimes the thing fixed in b.2. cannot be amended to the not-quite |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 783 | perfect commit it fixes, because that commit is buried deeply in a |
| 784 | patch series. That is exactly what interactive rebase is for: use it |
| 785 | after plenty of "a"s and "b"s, by rearranging and editing |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 786 | commits, and squashing multiple commits into one.</p></div> |
| 787 | <div class="para"><p>Start it with the last commit you want to retain as-is:</p></div> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 788 | <div class="literalblock"> |
| 789 | <div class="content"> |
| 790 | <pre><tt>git rebase -i <after-this-commit></tt></pre> |
| 791 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 792 | <div class="para"><p>An editor will be fired up with all the commits in your current branch |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 793 | (ignoring merge commits), which come after the given commit. You can |
| 794 | reorder the commits in this list to your heart's content, and you can |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 795 | remove them. The list looks more or less like this:</p></div> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 796 | <div class="listingblock"> |
| 797 | <div class="content"> |
| 798 | <pre><tt>pick deadbee The oneline of this commit |
| 799 | pick fa1afe1 The oneline of the next commit |
| 800 | ...</tt></pre> |
| 801 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 802 | <div class="para"><p>The oneline descriptions are purely for your pleasure; <em>git-rebase</em> will |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 803 | not look at them but at the commit names ("deadbee" and "fa1afe1" in this |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 804 | example), so do not delete or edit the names.</p></div> |
| 805 | <div class="para"><p>By replacing the command "pick" with the command "edit", you can tell |
| 806 | <em>git-rebase</em> to stop after applying that commit, so that you can edit |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 807 | the files and/or the commit message, amend the commit, and continue |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 808 | rebasing.</p></div> |
| 809 | <div class="para"><p>If you want to fold two or more commits into one, replace the command |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 810 | "pick" with "squash" for the second and subsequent commit. If the |
| 811 | commits had different authors, it will attribute the squashed commit to |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 812 | the author of the first commit.</p></div> |
| 813 | <div class="para"><p>In both cases, or when a "pick" does not succeed (because of merge |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 814 | errors), the loop will stop to let you fix things, and you can continue |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 815 | the loop with <tt>git rebase --continue</tt>.</p></div> |
| 816 | <div class="para"><p>For example, if you want to reorder the last 5 commits, such that what |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 817 | was HEAD~4 becomes the new HEAD. To achieve that, you would call |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 818 | <em>git-rebase</em> like this:</p></div> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 819 | <div class="listingblock"> |
| 820 | <div class="content"> |
| 821 | <pre><tt>$ git rebase -i HEAD~5</tt></pre> |
| 822 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 823 | <div class="para"><p>And move the first patch to the end of the list.</p></div> |
| 824 | <div class="para"><p>You might want to preserve merges, if you have a history like this:</p></div> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 825 | <div class="listingblock"> |
| 826 | <div class="content"> |
| 827 | <pre><tt> X |
| 828 | \ |
| 829 | A---M---B |
| 830 | / |
| 831 | ---o---O---P---Q</tt></pre> |
| 832 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 833 | <div class="para"><p>Suppose you want to rebase the side branch starting at "A" to "Q". Make |
| 834 | sure that the current HEAD is "B", and call</p></div> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 835 | <div class="listingblock"> |
| 836 | <div class="content"> |
| 837 | <pre><tt>$ git rebase -i -p --onto Q O</tt></pre> |
| 838 | </div></div> |
| 839 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 840 | <h2 id="_splitting_commits">SPLITTING COMMITS</h2> |
Junio C Hamano | dbb6459 | 2007-09-01 11:17:39 | [diff] [blame] | 841 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 842 | <div class="para"><p>In interactive mode, you can mark commits with the action "edit". However, |
| 843 | this does not necessarily mean that <em>git-rebase</em> expects the result of this |
Junio C Hamano | dbb6459 | 2007-09-01 11:17:39 | [diff] [blame] | 844 | edit to be exactly one commit. Indeed, you can undo the commit, or you can |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 845 | add other commits. This can be used to split a commit into two:</p></div> |
| 846 | <div class="ilist"><ul> |
Junio C Hamano | dbb6459 | 2007-09-01 11:17:39 | [diff] [blame] | 847 | <li> |
| 848 | <p> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 849 | Start an interactive rebase with <tt>git rebase -i <commit>^</tt>, where |
Junio C Hamano | dbb6459 | 2007-09-01 11:17:39 | [diff] [blame] | 850 | <commit> is the commit you want to split. In fact, any commit range |
| 851 | will do, as long as it contains that commit. |
| 852 | </p> |
| 853 | </li> |
| 854 | <li> |
| 855 | <p> |
| 856 | Mark the commit you want to split with the action "edit". |
| 857 | </p> |
| 858 | </li> |
| 859 | <li> |
| 860 | <p> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 861 | When it comes to editing that commit, execute <tt>git reset HEAD^</tt>. The |
Junio C Hamano | dbb6459 | 2007-09-01 11:17:39 | [diff] [blame] | 862 | effect is that the HEAD is rewound by one, and the index follows suit. |
| 863 | However, the working tree stays the same. |
| 864 | </p> |
| 865 | </li> |
| 866 | <li> |
| 867 | <p> |
| 868 | Now add the changes to the index that you want to have in the first |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 869 | commit. You can use <tt>git add</tt> (possibly interactively) or |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 870 | <em>git-gui</em> (or both) to do that. |
Junio C Hamano | dbb6459 | 2007-09-01 11:17:39 | [diff] [blame] | 871 | </p> |
| 872 | </li> |
| 873 | <li> |
| 874 | <p> |
| 875 | Commit the now-current index with whatever commit message is appropriate |
| 876 | now. |
| 877 | </p> |
| 878 | </li> |
| 879 | <li> |
| 880 | <p> |
| 881 | Repeat the last two steps until your working tree is clean. |
| 882 | </p> |
| 883 | </li> |
| 884 | <li> |
| 885 | <p> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 886 | Continue the rebase with <tt>git rebase --continue</tt>. |
Junio C Hamano | dbb6459 | 2007-09-01 11:17:39 | [diff] [blame] | 887 | </p> |
| 888 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 889 | </ul></div> |
| 890 | <div class="para"><p>If you are not absolutely sure that the intermediate revisions are |
Junio C Hamano | dbb6459 | 2007-09-01 11:17:39 | [diff] [blame] | 891 | consistent (they compile, pass the testsuite, etc.) you should use |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 892 | <em>git-stash</em> to stash away the not-yet-committed changes |
| 893 | after each commit, test, and amend the commit if fixes are necessary.</p></div> |
Junio C Hamano | dbb6459 | 2007-09-01 11:17:39 | [diff] [blame] | 894 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 895 | <h2 id="_authors">Authors</h2> |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 896 | <div class="sectionbody"> |
Junio C Hamano | 0868a30 | 2008-07-22 09:20:44 | [diff] [blame] | 897 | <div class="para"><p>Written by Junio C Hamano <gitster@pobox.com> and |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 898 | Johannes E. Schindelin <johannes.schindelin@gmx.de></p></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 899 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 900 | <h2 id="_documentation">Documentation</h2> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 901 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 902 | <div class="para"><p>Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.</p></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 903 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 904 | <h2 id="_git">GIT</h2> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 905 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 906 | <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 907 | </div> |
| 908 | <div id="footer"> |
| 909 | <div id="footer-text"> |
Junio C Hamano | 0868a30 | 2008-07-22 09:20:44 | [diff] [blame] | 910 | Last updated 2008-07-22 09:19:14 UTC |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 911 | </div> |
| 912 | </div> |
| 913 | </body> |
| 914 | </html> |