blob: c0139ed782ebbaebb665e50bcf6cb1403f1dbedb [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231<!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 Hamano7bd050f2011-09-22 06:32:226<meta name="generator" content="AsciiDoc 8.5.2" />
Junio C Hamano68cf15a2010-11-06 01:01:597<title>git-rebase(1)</title>
Junio C Hamano1a4e8412005-12-27 08:17:238<style type="text/css">
9/* Debug borders */
10p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11/*
12 border: 1px solid red;
13*/
14}
15
16body {
17 margin: 1em 5% 1em 5%;
18}
19
Junio C Hamanoba4b9282008-07-06 05:20:3120a {
21 color: blue;
22 text-decoration: underline;
23}
24a:visited {
25 color: fuchsia;
26}
Junio C Hamano1a4e8412005-12-27 08:17:2327
28em {
29 font-style: italic;
Junio C Hamano68cf15a2010-11-06 01:01:5930 color: navy;
Junio C Hamano1a4e8412005-12-27 08:17:2331}
32
33strong {
34 font-weight: bold;
Junio C Hamano68cf15a2010-11-06 01:01:5935 color: #083194;
Junio C Hamano1a4e8412005-12-27 08:17:2336}
37
38tt {
39 color: navy;
40}
41
42h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
48}
49
Junio C Hamanoba4b9282008-07-06 05:20:3150h1, h2, h3 {
Junio C Hamano1a4e8412005-12-27 08:17:2351 border-bottom: 2px solid silver;
52}
53h2 {
Junio C Hamano1a4e8412005-12-27 08:17:2354 padding-top: 0.5em;
55}
Junio C Hamanoba4b9282008-07-06 05:20:3156h3 {
57 float: left;
58}
59h3 + * {
60 clear: left;
61}
Junio C Hamano1a4e8412005-12-27 08:17:2362
63div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
66}
67
68hr {
69 border: 1px solid silver;
70}
71
72p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
75}
76
Junio C Hamano68cf15a2010-11-06 01:01:5977ul, ol, li > p {
78 margin-top: 0;
79}
80
Junio C Hamano1a4e8412005-12-27 08:17:2381pre {
82 padding: 0;
83 margin: 0;
84}
85
86span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
Junio C Hamanoba4b9282008-07-06 05:20:3190 font-size: 1.1em;
Junio C Hamano1a4e8412005-12-27 08:17:2391}
92span#email {
93}
Junio C Hamano68cf15a2010-11-06 01:01:5994span#revnumber, span#revdate, span#revremark {
Junio C Hamano1a4e8412005-12-27 08:17:2395 font-family: sans-serif;
96}
97
98div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
104}
105div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
108}
109div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
112}
113
Junio C Hamano68cf15a2010-11-06 01:01:59114div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
117}
Junio C Hamano1a4e8412005-12-27 08:17:23118div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120div.admonitionblock {
Junio C Hamano7bd050f2011-09-22 06:32:22121 margin-top: 1.0em;
Junio C Hamano1a4e8412005-12-27 08:17:23122 margin-bottom: 1.5em;
123}
124div.admonitionblock {
Junio C Hamano7bd050f2011-09-22 06:32:22125 margin-top: 2.0em;
126 margin-bottom: 2.0em;
127 margin-right: 10%;
128 color: #606060;
Junio C Hamano1a4e8412005-12-27 08:17:23129}
130
131div.content { /* Block element content. */
132 padding: 0;
133}
134
135/* Block element titles. */
136div.title, caption.title {
Junio C Hamano68cf15a2010-11-06 01:01:59137 color: #527bbd;
Junio C Hamano1a4e8412005-12-27 08:17:23138 font-family: sans-serif;
139 font-weight: bold;
140 text-align: left;
141 margin-top: 1.0em;
142 margin-bottom: 0.5em;
143}
144div.title + * {
145 margin-top: 0;
146}
147
148td div.title:first-child {
149 margin-top: 0.0em;
150}
151div.content div.title:first-child {
152 margin-top: 0.0em;
153}
154div.content + div.title {
155 margin-top: 0.0em;
156}
157
158div.sidebarblock > div.content {
159 background: #ffffee;
160 border: 1px solid silver;
161 padding: 0.5em;
162}
163
164div.listingblock > div.content {
165 border: 1px solid silver;
166 background: #f4f4f4;
167 padding: 0.5em;
168}
169
Junio C Hamano7bd050f2011-09-22 06:32:22170div.quoteblock, div.verseblock {
171 padding-left: 1.0em;
172 margin-left: 1.0em;
Junio C Hamano68cf15a2010-11-06 01:01:59173 margin-right: 10%;
Junio C Hamano7bd050f2011-09-22 06:32:22174 border-left: 5px solid #dddddd;
175 color: #777777;
Junio C Hamano1a4e8412005-12-27 08:17:23176}
Junio C Hamano7bd050f2011-09-22 06:32:22177
Junio C Hamano68cf15a2010-11-06 01:01:59178div.quoteblock > div.attribution {
179 padding-top: 0.5em;
Junio C Hamano1a4e8412005-12-27 08:17:23180 text-align: right;
181}
Junio C Hamano68cf15a2010-11-06 01:01:59182
Junio C Hamano68cf15a2010-11-06 01:01:59183div.verseblock > div.content {
184 white-space: pre;
185}
186div.verseblock > div.attribution {
187 padding-top: 0.75em;
188 text-align: left;
189}
190/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
Junio C Hamanoba4b9282008-07-06 05:20:31191div.verseblock + div.attribution {
192 text-align: left;
193}
Junio C Hamano1a4e8412005-12-27 08:17:23194
195div.admonitionblock .icon {
196 vertical-align: top;
197 font-size: 1.1em;
198 font-weight: bold;
199 text-decoration: underline;
200 color: #527bbd;
201 padding-right: 0.5em;
202}
203div.admonitionblock td.content {
204 padding-left: 0.5em;
Junio C Hamano7bd050f2011-09-22 06:32:22205 border-left: 3px solid #dddddd;
Junio C Hamano1a4e8412005-12-27 08:17:23206}
207
208div.exampleblock > div.content {
Junio C Hamano7bd050f2011-09-22 06:32:22209 border-left: 3px solid #dddddd;
210 padding-left: 0.5em;
Junio C Hamano1a4e8412005-12-27 08:17:23211}
212
Junio C Hamano1a4e8412005-12-27 08:17:23213div.imageblock div.content { padding-left: 0; }
Junio C Hamano1a4e8412005-12-27 08:17:23214span.image img { border-style: none; }
Junio C Hamano68cf15a2010-11-06 01:01:59215a.image:visited { color: white; }
Junio C Hamano1a4e8412005-12-27 08:17:23216
217dl {
218 margin-top: 0.8em;
219 margin-bottom: 0.8em;
220}
221dt {
222 margin-top: 0.5em;
223 margin-bottom: 0;
Junio C Hamano68cf15a2010-11-06 01:01:59224 font-style: normal;
225 color: navy;
Junio C Hamano1a4e8412005-12-27 08:17:23226}
227dd > *:first-child {
Junio C Hamano68cf15a2010-11-06 01:01:59228 margin-top: 0.1em;
Junio C Hamano1a4e8412005-12-27 08:17:23229}
230
231ul, ol {
232 list-style-position: outside;
233}
Junio C Hamano68cf15a2010-11-06 01:01:59234ol.arabic {
235 list-style-type: decimal;
236}
237ol.loweralpha {
Junio C Hamano1a4e8412005-12-27 08:17:23238 list-style-type: lower-alpha;
239}
Junio C Hamano68cf15a2010-11-06 01:01:59240ol.upperalpha {
241 list-style-type: upper-alpha;
242}
243ol.lowerroman {
244 list-style-type: lower-roman;
245}
246ol.upperroman {
247 list-style-type: upper-roman;
248}
249
250div.compact ul, div.compact ol,
251div.compact p, div.compact p,
252div.compact div, div.compact div {
253 margin-top: 0.1em;
254 margin-bottom: 0.1em;
255}
Junio C Hamano1a4e8412005-12-27 08:17:23256
257div.tableblock > table {
Junio C Hamanoba4b9282008-07-06 05:20:31258 border: 3px solid #527bbd;
Junio C Hamano1a4e8412005-12-27 08:17:23259}
Junio C Hamano7bd050f2011-09-22 06:32:22260thead, p.table.header {
Junio C Hamano1a4e8412005-12-27 08:17:23261 font-family: sans-serif;
262 font-weight: bold;
263}
264tfoot {
265 font-weight: bold;
266}
Junio C Hamano68cf15a2010-11-06 01:01:59267td > div.verse {
268 white-space: pre;
269}
270p.table {
271 margin-top: 0;
272}
273/* Because the table frame attribute is overriden by CSS in most browsers. */
274div.tableblock > table[frame="void"] {
275 border-style: none;
276}
277div.tableblock > table[frame="hsides"] {
278 border-left-style: none;
279 border-right-style: none;
280}
281div.tableblock > table[frame="vsides"] {
282 border-top-style: none;
283 border-bottom-style: none;
284}
Junio C Hamano1a4e8412005-12-27 08:17:23285
Junio C Hamano68cf15a2010-11-06 01:01:59286
287div.hdlist {
Junio C Hamano1a4e8412005-12-27 08:17:23288 margin-top: 0.8em;
289 margin-bottom: 0.8em;
290}
Junio C Hamano68cf15a2010-11-06 01:01:59291div.hdlist tr {
292 padding-bottom: 15px;
Junio C Hamanoba4b9282008-07-06 05:20:31293}
Junio C Hamano68cf15a2010-11-06 01:01:59294dt.hdlist1.strong, td.hdlist1.strong {
295 font-weight: bold;
296}
297td.hdlist1 {
Junio C Hamano1a4e8412005-12-27 08:17:23298 vertical-align: top;
Junio C Hamano68cf15a2010-11-06 01:01:59299 font-style: normal;
Junio C Hamano1a4e8412005-12-27 08:17:23300 padding-right: 0.8em;
Junio C Hamano68cf15a2010-11-06 01:01:59301 color: navy;
Junio C Hamano1a4e8412005-12-27 08:17:23302}
Junio C Hamano68cf15a2010-11-06 01:01:59303td.hdlist2 {
Junio C Hamano1a4e8412005-12-27 08:17:23304 vertical-align: top;
305}
Junio C Hamano68cf15a2010-11-06 01:01:59306div.hdlist.compact tr {
307 margin: 0;
308 padding-bottom: 0;
309}
310
311.comment {
312 background: yellow;
313}
Junio C Hamano1a4e8412005-12-27 08:17:23314
Junio C Hamano7bd050f2011-09-22 06:32:22315.footnote, .footnoteref {
316 font-size: 0.8em;
317}
318
319span.footnote, span.footnoteref {
320 vertical-align: super;
321}
322
323#footnotes {
324 margin: 20px 0 20px 0;
325 padding: 7px 0 0 0;
326}
327
328#footnotes div.footnote {
329 margin: 0 0 5px 0;
330}
331
332#footnotes hr {
333 border: none;
334 border-top: 1px solid silver;
335 height: 1px;
336 text-align: left;
337 margin-left: 0;
338 width: 20%;
339 min-width: 100px;
340}
341
342
Junio C Hamano1a4e8412005-12-27 08:17:23343@media print {
344 div#footer-badges { display: none; }
345}
Junio C Hamanoba4b9282008-07-06 05:20:31346
Junio C Hamano7bd050f2011-09-22 06:32:22347div#toc {
348 margin-bottom: 2.5em;
349}
350
Junio C Hamanoba4b9282008-07-06 05:20:31351div#toctitle {
352 color: #527bbd;
353 font-family: sans-serif;
354 font-size: 1.1em;
355 font-weight: bold;
356 margin-top: 1.0em;
357 margin-bottom: 0.1em;
358}
359
360div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
361 margin-top: 0;
362 margin-bottom: 0;
363}
364div.toclevel2 {
365 margin-left: 2em;
366 font-size: 0.9em;
367}
368div.toclevel3 {
369 margin-left: 4em;
370 font-size: 0.9em;
371}
372div.toclevel4 {
373 margin-left: 6em;
374 font-size: 0.9em;
375}
Junio C Hamano68cf15a2010-11-06 01:01:59376/* Overrides for manpage documents */
377h1 {
378 padding-top: 0.5em;
379 padding-bottom: 0.5em;
380 border-top: 2px solid silver;
381 border-bottom: 2px solid silver;
382}
383h2 {
384 border-style: none;
385}
386div.sectionbody {
387 margin-left: 5%;
388}
389
390@media print {
391 div#toc { display: none; }
392}
393
Junio C Hamano1a4e8412005-12-27 08:17:23394/* Workarounds for IE6's broken and incomplete CSS2. */
395
396div.sidebar-content {
397 background: #ffffee;
398 border: 1px solid silver;
399 padding: 0.5em;
400}
401div.sidebar-title, div.image-title {
Junio C Hamano68cf15a2010-11-06 01:01:59402 color: #527bbd;
Junio C Hamano1a4e8412005-12-27 08:17:23403 font-family: sans-serif;
404 font-weight: bold;
405 margin-top: 0.0em;
406 margin-bottom: 0.5em;
407}
408
409div.listingblock div.content {
410 border: 1px solid silver;
411 background: #f4f4f4;
412 padding: 0.5em;
413}
414
Junio C Hamano68cf15a2010-11-06 01:01:59415div.quoteblock-attribution {
416 padding-top: 0.5em;
417 text-align: right;
418}
419
420div.verseblock-content {
421 white-space: pre;
422}
423div.verseblock-attribution {
424 padding-top: 0.75em;
425 text-align: left;
Junio C Hamano1a4e8412005-12-27 08:17:23426}
427
428div.exampleblock-content {
Junio C Hamano7bd050f2011-09-22 06:32:22429 border-left: 3px solid #dddddd;
Junio C Hamano1a4e8412005-12-27 08:17:23430 padding-left: 0.5em;
431}
Junio C Hamanoba4b9282008-07-06 05:20:31432
433/* IE6 sets dynamically generated links as visited. */
434div#toc a:visited { color: blue; }
Junio C Hamano1a4e8412005-12-27 08:17:23435</style>
Junio C Hamano7bd050f2011-09-22 06:32:22436<script type="text/javascript">
437/*<![CDATA[*/
438window.onload = function(){asciidoc.footnotes();}
439var asciidoc = { // Namespace.
440
441/////////////////////////////////////////////////////////////////////
442// Table Of Contents generator
443/////////////////////////////////////////////////////////////////////
444
445/* Author: Mihai Bazon, September 2002
446 * http://students.infoiasi.ro/~mishoo
447 *
448 * Table Of Content generator
449 * Version: 0.4
450 *
451 * Feel free to use this script under the terms of the GNU General Public
452 * License, as long as you do not remove or alter this notice.
453 */
454
455 /* modified by Troy D. Hanson, September 2006. License: GPL */
456 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
457
458// toclevels = 1..4.
459toc: function (toclevels) {
460
461 function getText(el) {
462 var text = "";
463 for (var i = el.firstChild; i != null; i = i.nextSibling) {
464 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
465 text += i.data;
466 else if (i.firstChild != null)
467 text += getText(i);
468 }
469 return text;
470 }
471
472 function TocEntry(el, text, toclevel) {
473 this.element = el;
474 this.text = text;
475 this.toclevel = toclevel;
476 }
477
478 function tocEntries(el, toclevels) {
479 var result = new Array;
480 var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
481 // Function that scans the DOM tree for header elements (the DOM2
482 // nodeIterator API would be a better technique but not supported by all
483 // browsers).
484 var iterate = function (el) {
485 for (var i = el.firstChild; i != null; i = i.nextSibling) {
486 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
487 var mo = re.exec(i.tagName);
488 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
489 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
490 }
491 iterate(i);
492 }
493 }
494 }
495 iterate(el);
496 return result;
497 }
498
499 var toc = document.getElementById("toc");
500 var entries = tocEntries(document.getElementById("content"), toclevels);
501 for (var i = 0; i < entries.length; ++i) {
502 var entry = entries[i];
503 if (entry.element.id == "")
504 entry.element.id = "_toc_" + i;
505 var a = document.createElement("a");
506 a.href = "#" + entry.element.id;
507 a.appendChild(document.createTextNode(entry.text));
508 var div = document.createElement("div");
509 div.appendChild(a);
510 div.className = "toclevel" + entry.toclevel;
511 toc.appendChild(div);
512 }
513 if (entries.length == 0)
514 toc.parentNode.removeChild(toc);
515},
516
517
518/////////////////////////////////////////////////////////////////////
519// Footnotes generator
520/////////////////////////////////////////////////////////////////////
521
522/* Based on footnote generation code from:
523 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
524 */
525
526footnotes: function () {
527 var cont = document.getElementById("content");
528 var noteholder = document.getElementById("footnotes");
529 var spans = cont.getElementsByTagName("span");
530 var refs = {};
531 var n = 0;
532 for (i=0; i<spans.length; i++) {
533 if (spans[i].className == "footnote") {
534 n++;
535 // Use [\s\S] in place of . so multi-line matches work.
536 // Because JavaScript has no s (dotall) regex flag.
537 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
538 noteholder.innerHTML +=
539 "<div class='footnote' id='_footnote_" + n + "'>" +
540 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
541 n + "</a>. " + note + "</div>";
542 spans[i].innerHTML =
543 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
544 "' title='View footnote' class='footnote'>" + n + "</a>]";
545 var id =spans[i].getAttribute("id");
546 if (id != null) refs["#"+id] = n;
547 }
548 }
549 if (n == 0)
550 noteholder.parentNode.removeChild(noteholder);
551 else {
552 // Process footnoterefs.
553 for (i=0; i<spans.length; i++) {
554 if (spans[i].className == "footnoteref") {
555 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
556 href = href.match(/#.*/)[0]; // Because IE return full URL.
557 n = refs[href];
558 spans[i].innerHTML =
559 "[<a href='#_footnote_" + n +
560 "' title='View footnote' class='footnote'>" + n + "</a>]";
561 }
562 }
563 }
564}
565
566}
567/*]]>*/
568</script>
Junio C Hamano1a4e8412005-12-27 08:17:23569</head>
570<body>
571<div id="header">
572<h1>
573git-rebase(1) Manual Page
574</h1>
575<h2>NAME</h2>
576<div class="sectionbody">
577<p>git-rebase -
Junio C Hamano7c73c662007-01-19 00:37:50578 Forward-port local commits to the updated upstream head
Junio C Hamano1a4e8412005-12-27 08:17:23579</p>
580</div>
581</div>
Junio C Hamano7bd050f2011-09-22 06:32:22582<div id="content">
Junio C Hamano68cf15a2010-11-06 01:01:59583<h2 id="_synopsis">SYNOPSIS</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23584<div class="sectionbody">
Junio C Hamanoa9b8d242007-05-19 04:51:55585<div class="verseblock">
Junio C Hamano68cf15a2010-11-06 01:01:59586<div class="verseblock-content"><em>git rebase</em> [-i | --interactive] [options] [--onto &lt;newbase&gt;]
Junio C Hamanob02377c2011-04-28 22:26:02587 [&lt;upstream&gt;] [&lt;branch&gt;]
Junio C Hamanobd53dbf2009-01-18 18:26:37588<em>git rebase</em> [-i | --interactive] [options] --onto &lt;newbase&gt;
Junio C Hamano15567bc2011-07-23 00:51:59589 --root [&lt;branch&gt;]
590<em>git rebase</em> --continue | --skip | --abort</div>
Junio C Hamano68cf15a2010-11-06 01:01:59591<div class="verseblock-attribution">
592</div></div>
Junio C Hamano1a4e8412005-12-27 08:17:23593</div>
Junio C Hamanoba4b9282008-07-06 05:20:31594<h2 id="_description">DESCRIPTION</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23595<div class="sectionbody">
Junio C Hamano68cf15a2010-11-06 01:01:59596<div class="paragraph"><p>If &lt;branch&gt; is specified, <em>git rebase</em> will perform an automatic
Junio C Hamano89d4e0f2007-02-18 00:34:59597<tt>git checkout &lt;branch&gt;</tt> before doing anything else. Otherwise
Junio C Hamanoba4b9282008-07-06 05:20:31598it remains on the current branch.</p></div>
Junio C Hamanob02377c2011-04-28 22:26:02599<div class="paragraph"><p>If &lt;upstream&gt; is not specified, the upstream configured in
600branch.&lt;name&gt;.remote and branch.&lt;name&gt;.merge options will be used; see
601<a href="git-config.html">git-config(1)</a> for details. If you are currently not on any
602branch or if the current branch does not have a configured upstream,
603the rebase will abort.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:59604<div class="paragraph"><p>All changes made by commits in the current branch but that are not
Junio C Hamano89d4e0f2007-02-18 00:34:59605in &lt;upstream&gt; are saved to a temporary area. This is the same set
Junio C Hamanobd53dbf2009-01-18 18:26:37606of commits that would be shown by <tt>git log &lt;upstream&gt;..HEAD</tt> (or
607<tt>git log HEAD</tt>, if --root is specified).</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:59608<div class="paragraph"><p>The current branch is reset to &lt;upstream&gt;, or &lt;newbase&gt; if the
Junio C Hamano89d4e0f2007-02-18 00:34:59609--onto option was supplied. This has the exact same effect as
Junio C Hamano38ddcce2008-07-15 15:49:03610<tt>git reset --hard &lt;upstream&gt;</tt> (or &lt;newbase&gt;). ORIG_HEAD is set
611to point at the tip of the branch before the reset.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:59612<div class="paragraph"><p>The commits that were previously saved into the temporary area are
Junio C Hamano764a6672007-10-23 01:23:31613then reapplied to the current branch, one by one, in order. Note that
614any commits in HEAD which introduce the same textual changes as a commit
615in HEAD..&lt;upstream&gt; are omitted (i.e., a patch already accepted upstream
Junio C Hamanoba4b9282008-07-06 05:20:31616with a different commit message or timestamp will be skipped).</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:59617<div class="paragraph"><p>It is possible that a merge failure will prevent this process from being
Junio C Hamano6112cad2006-05-02 07:28:06618completely automatic. You will have to resolve any such merge failure
Junio C Hamano6959c6c2006-05-17 10:34:11619and run <tt>git rebase --continue</tt>. Another option is to bypass the commit
Junio C Hamano15567bc2011-07-23 00:51:59620that caused the merge failure with <tt>git rebase --skip</tt>. To check out the
Junio C Hamano0868a302008-07-22 09:20:44621original &lt;branch&gt; and remove the .git/rebase-apply working files, use the
622command <tt>git rebase --abort</tt> instead.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:59623<div class="paragraph"><p>Assume the following history exists and the current branch is "topic":</p></div>
Junio C Hamano6112cad2006-05-02 07:28:06624<div class="listingblock">
Junio C Hamano7e9f6b72006-02-22 10:44:55625<div class="content">
Junio C Hamano6112cad2006-05-02 07:28:06626<pre><tt> A---B---C topic
627 /
628 D---E---F---G master</tt></pre>
Junio C Hamano7e9f6b72006-02-22 10:44:55629</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59630<div class="paragraph"><p>From this point, the result of either of the following commands:</p></div>
Junio C Hamano7e9f6b72006-02-22 10:44:55631<div class="literalblock">
632<div class="content">
Junio C Hamanofce7c7e2008-07-02 03:06:38633<pre><tt>git rebase master
634git rebase master topic</tt></pre>
Junio C Hamano7e9f6b72006-02-22 10:44:55635</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59636<div class="paragraph"><p>would be:</p></div>
Junio C Hamano6112cad2006-05-02 07:28:06637<div class="listingblock">
Junio C Hamano7e9f6b72006-02-22 10:44:55638<div class="content">
Junio C Hamano6112cad2006-05-02 07:28:06639<pre><tt> A'--B'--C' topic
640 /
641 D---E---F---G master</tt></pre>
Junio C Hamano7e9f6b72006-02-22 10:44:55642</div></div>
Junio C Hamano92faa802011-03-15 01:00:18643<div class="paragraph"><p><strong>NOTE:</strong> The latter form is just a short-hand of <tt>git checkout topic</tt>
644followed by <tt>git rebase master</tt>. When rebase exits <tt>topic</tt> will
645remain the checked-out branch.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:59646<div class="paragraph"><p>If the upstream branch already contains a change you have made (e.g.,
Junio C Hamano764a6672007-10-23 01:23:31647because you mailed a patch which was applied upstream), then that commit
Junio C Hamano68cf15a2010-11-06 01:01:59648will be skipped. For example, running &#8216;git rebase master` on the
649following history (in which A&#8217; and A introduce the same set of changes,
Junio C Hamanoba4b9282008-07-06 05:20:31650but have different committer information):</p></div>
Junio C Hamano764a6672007-10-23 01:23:31651<div class="listingblock">
652<div class="content">
653<pre><tt> A---B---C topic
654 /
655 D---E---A'---F master</tt></pre>
656</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59657<div class="paragraph"><p>will result in:</p></div>
Junio C Hamano764a6672007-10-23 01:23:31658<div class="listingblock">
659<div class="content">
660<pre><tt> B'---C' topic
661 /
662 D---E---A'---F master</tt></pre>
663</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59664<div class="paragraph"><p>Here is how you would transplant a topic branch based on one
Junio C Hamanod8c9d432006-11-07 07:19:13665branch to another, to pretend that you forked the topic branch
Junio C Hamanoba4b9282008-07-06 05:20:31666from the latter branch, using <tt>rebase --onto</tt>.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:59667<div class="paragraph"><p>First let&#8217;s assume your <em>topic</em> is based on branch <em>next</em>.
Junio C Hamanoa476efa2008-10-10 15:31:42668For example, a feature developed in <em>topic</em> depends on some
Junio C Hamanoba4b9282008-07-06 05:20:31669functionality which is found in <em>next</em>.</p></div>
Junio C Hamano6112cad2006-05-02 07:28:06670<div class="listingblock">
Junio C Hamano7e9f6b72006-02-22 10:44:55671<div class="content">
Junio C Hamanod8c9d432006-11-07 07:19:13672<pre><tt> o---o---o---o---o master
673 \
674 o---o---o---o---o next
675 \
676 o---o---o topic</tt></pre>
Junio C Hamano7e9f6b72006-02-22 10:44:55677</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59678<div class="paragraph"><p>We want to make <em>topic</em> forked from branch <em>master</em>; for example,
Junio C Hamanoa476efa2008-10-10 15:31:42679because the functionality on which <em>topic</em> depends was merged into the
680more stable <em>master</em> branch. We want our tree to look like this:</p></div>
Junio C Hamanod8c9d432006-11-07 07:19:13681<div class="listingblock">
682<div class="content">
683<pre><tt> o---o---o---o---o master
684 | \
685 | o'--o'--o' topic
686 \
687 o---o---o---o---o next</tt></pre>
688</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59689<div class="paragraph"><p>We can get this using the following command:</p></div>
Junio C Hamanod8c9d432006-11-07 07:19:13690<div class="literalblock">
691<div class="content">
Junio C Hamanofce7c7e2008-07-02 03:06:38692<pre><tt>git rebase --onto master next topic</tt></pre>
Junio C Hamanod8c9d432006-11-07 07:19:13693</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59694<div class="paragraph"><p>Another example of --onto option is to rebase part of a
Junio C Hamanoba4b9282008-07-06 05:20:31695branch. If we have the following situation:</p></div>
Junio C Hamanod8c9d432006-11-07 07:19:13696<div class="listingblock">
697<div class="content">
698<pre><tt> H---I---J topicB
699 /
700 E---F---G topicA
701 /
702 A---B---C---D master</tt></pre>
703</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59704<div class="paragraph"><p>then the command</p></div>
Junio C Hamanod8c9d432006-11-07 07:19:13705<div class="literalblock">
706<div class="content">
Junio C Hamanofce7c7e2008-07-02 03:06:38707<pre><tt>git rebase --onto master topicA topicB</tt></pre>
Junio C Hamanod8c9d432006-11-07 07:19:13708</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59709<div class="paragraph"><p>would result in:</p></div>
Junio C Hamanod8c9d432006-11-07 07:19:13710<div class="listingblock">
711<div class="content">
712<pre><tt> H'--I'--J' topicB
713 /
714 | E---F---G topicA
715 |/
716 A---B---C---D master</tt></pre>
717</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59718<div class="paragraph"><p>This is useful when topicB does not depend on topicA.</p></div>
719<div class="paragraph"><p>A range of commits could also be removed with rebase. If we have
Junio C Hamanoba4b9282008-07-06 05:20:31720the following situation:</p></div>
Junio C Hamano42f855f2007-02-06 00:09:38721<div class="listingblock">
722<div class="content">
723<pre><tt> E---F---G---H---I---J topicA</tt></pre>
724</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59725<div class="paragraph"><p>then the command</p></div>
Junio C Hamano42f855f2007-02-06 00:09:38726<div class="literalblock">
727<div class="content">
Junio C Hamanofce7c7e2008-07-02 03:06:38728<pre><tt>git rebase --onto topicA~5 topicA~3 topicA</tt></pre>
Junio C Hamano42f855f2007-02-06 00:09:38729</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59730<div class="paragraph"><p>would result in the removal of commits F and G:</p></div>
Junio C Hamano42f855f2007-02-06 00:09:38731<div class="listingblock">
732<div class="content">
733<pre><tt> E---H'---I'---J' topicA</tt></pre>
734</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59735<div class="paragraph"><p>This is useful if F and G were flawed in some way, or should not be
Junio C Hamano42f855f2007-02-06 00:09:38736part of topicA. Note that the argument to --onto and the &lt;upstream&gt;
Junio C Hamanoba4b9282008-07-06 05:20:31737parameter can be any valid commit-ish.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:59738<div class="paragraph"><p>In case of conflict, <em>git rebase</em> will stop at the first problematic commit
Junio C Hamano1aa40d22010-01-21 17:46:43739and leave conflict markers in the tree. You can use <em>git diff</em> to locate
Junio C Hamano6112cad2006-05-02 07:28:06740the markers (&lt;&lt;&lt;&lt;&lt;&lt;) and make edits to resolve the conflict. For each
741file you edit, you need to tell git that the conflict has been resolved,
Junio C Hamanoba4b9282008-07-06 05:20:31742typically this would be done with</p></div>
Junio C Hamanof02e09f2006-03-27 07:51:03743<div class="literalblock">
744<div class="content">
Junio C Hamano89d4e0f2007-02-18 00:34:59745<pre><tt>git add &lt;filename&gt;</tt></pre>
Junio C Hamano6112cad2006-05-02 07:28:06746</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59747<div class="paragraph"><p>After resolving the conflict manually and updating the index with the
Junio C Hamanoba4b9282008-07-06 05:20:31748desired resolution, you can continue the rebasing process with</p></div>
Junio C Hamano6112cad2006-05-02 07:28:06749<div class="literalblock">
750<div class="content">
751<pre><tt>git rebase --continue</tt></pre>
Junio C Hamanof02e09f2006-03-27 07:51:03752</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:59753<div class="paragraph"><p>Alternatively, you can undo the <em>git rebase</em> with</p></div>
Junio C Hamanof02e09f2006-03-27 07:51:03754<div class="literalblock">
755<div class="content">
Junio C Hamano6112cad2006-05-02 07:28:06756<pre><tt>git rebase --abort</tt></pre>
Junio C Hamanof02e09f2006-03-27 07:51:03757</div></div>
Junio C Hamano1a4e8412005-12-27 08:17:23758</div>
Junio C Hamanoea6a7642009-03-11 23:56:19759<h2 id="_configuration">CONFIGURATION</h2>
760<div class="sectionbody">
Junio C Hamano68cf15a2010-11-06 01:01:59761<div class="dlist"><dl>
762<dt class="hdlist1">
Junio C Hamanoea6a7642009-03-11 23:56:19763rebase.stat
764</dt>
765<dd>
766<p>
767 Whether to show a diffstat of what changed upstream since the last
768 rebase. False by default.
769</p>
770</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59771<dt class="hdlist1">
Junio C Hamano075ae872010-09-01 18:43:07772rebase.autosquash
773</dt>
774<dd>
775<p>
776 If set to true enable <em>--autosquash</em> option by default.
777</p>
778</dd>
Junio C Hamanoea6a7642009-03-11 23:56:19779</dl></div>
780</div>
Junio C Hamanoba4b9282008-07-06 05:20:31781<h2 id="_options">OPTIONS</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23782<div class="sectionbody">
Junio C Hamano68cf15a2010-11-06 01:01:59783<div class="dlist"><dl>
784<dt class="hdlist1">
Junio C Hamano7e9f6b72006-02-22 10:44:55785&lt;newbase&gt;
786</dt>
787<dd>
788<p>
789 Starting point at which to create the new commits. If the
790 --onto option is not specified, the starting point is
Junio C Hamano42f855f2007-02-06 00:09:38791 &lt;upstream&gt;. May be any valid commit, and not just an
792 existing branch name.
Junio C Hamano7e9f6b72006-02-22 10:44:55793</p>
Junio C Hamano68cf15a2010-11-06 01:01:59794<div class="paragraph"><p>As a special case, you may use "A...B" as a shortcut for the
Junio C Hamanoe32ec8b2010-06-02 23:32:31795merge base of A and B if there is exactly one merge base. You can
796leave out at most one of A and B, in which case it defaults to HEAD.</p></div>
Junio C Hamano7e9f6b72006-02-22 10:44:55797</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59798<dt class="hdlist1">
Junio C Hamano1a4e8412005-12-27 08:17:23799&lt;upstream&gt;
800</dt>
801<dd>
802<p>
Junio C Hamano42f855f2007-02-06 00:09:38803 Upstream branch to compare against. May be any valid commit,
Junio C Hamanob02377c2011-04-28 22:26:02804 not just an existing branch name. Defaults to the configured
805 upstream for the current branch.
Junio C Hamano1a4e8412005-12-27 08:17:23806</p>
807</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59808<dt class="hdlist1">
Junio C Hamano2b135272006-03-18 07:45:42809&lt;branch&gt;
Junio C Hamano1a4e8412005-12-27 08:17:23810</dt>
811<dd>
812<p>
813 Working branch; defaults to HEAD.
814</p>
815</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59816<dt class="hdlist1">
Junio C Hamano6112cad2006-05-02 07:28:06817--continue
818</dt>
819<dd>
820<p>
821 Restart the rebasing process after having resolved a merge conflict.
822</p>
823</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59824<dt class="hdlist1">
Junio C Hamano6112cad2006-05-02 07:28:06825--abort
826</dt>
827<dd>
828<p>
Junio C Hamano15567bc2011-07-23 00:51:59829 Abort the rebase operation and reset HEAD to the original
830 branch. If &lt;branch&gt; was provided when the rebase operation was
831 started, then HEAD will be reset to &lt;branch&gt;. Otherwise HEAD
832 will be reset to where it was when the rebase operation was
833 started.
Junio C Hamano6112cad2006-05-02 07:28:06834</p>
835</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59836<dt class="hdlist1">
Junio C Hamano97f518c2006-06-22 19:49:35837--skip
838</dt>
839<dd>
840<p>
841 Restart the rebasing process by skipping the current patch.
Junio C Hamano97f518c2006-06-22 19:49:35842</p>
843</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59844<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:47845-m
846</dt>
Junio C Hamano68cf15a2010-11-06 01:01:59847<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:47848--merge
Junio C Hamano97f518c2006-06-22 19:49:35849</dt>
850<dd>
851<p>
852 Use merging strategies to rebase. When the recursive (default) merge
853 strategy is used, this allows rebase to be aware of renames on the
854 upstream side.
855</p>
Junio C Hamano68cf15a2010-11-06 01:01:59856<div class="paragraph"><p>Note that a rebase merge works by replaying each commit from the working
Junio C Hamanobf984de2009-11-23 06:11:19857branch on top of the &lt;upstream&gt; branch. Because of this, when a merge
858conflict happens, the side reported as <em>ours</em> is the so-far rebased
859series, starting with &lt;upstream&gt;, and <em>theirs</em> is the working branch. In
860other words, the sides are swapped.</p></div>
Junio C Hamano97f518c2006-06-22 19:49:35861</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59862<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:47863-s &lt;strategy&gt;
864</dt>
Junio C Hamano68cf15a2010-11-06 01:01:59865<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:47866--strategy=&lt;strategy&gt;
Junio C Hamano97f518c2006-06-22 19:49:35867</dt>
868<dd>
869<p>
Junio C Hamano52d5def2009-05-21 16:27:43870 Use the given merge strategy.
Junio C Hamano1aa40d22010-01-21 17:46:43871 If there is no <tt>-s</tt> option <em>git merge-recursive</em> is used
Junio C Hamanobf984de2009-11-23 06:11:19872 instead. This implies --merge.
Junio C Hamano97f518c2006-06-22 19:49:35873</p>
Junio C Hamano68cf15a2010-11-06 01:01:59874<div class="paragraph"><p>Because <em>git rebase</em> replays each commit from the working branch
Junio C Hamanobf984de2009-11-23 06:11:19875on top of the &lt;upstream&gt; branch using the given strategy, using
876the <em>ours</em> strategy simply discards all patches from the &lt;branch&gt;,
877which makes little sense.</p></div>
Junio C Hamano97f518c2006-06-22 19:49:35878</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59879<dt class="hdlist1">
Junio C Hamano619596a2010-08-18 22:15:35880-X &lt;strategy-option&gt;
881</dt>
Junio C Hamano68cf15a2010-11-06 01:01:59882<dt class="hdlist1">
Junio C Hamano619596a2010-08-18 22:15:35883--strategy-option=&lt;strategy-option&gt;
884</dt>
885<dd>
886<p>
887 Pass the &lt;strategy-option&gt; through to the merge strategy.
888 This implies <tt>--merge</tt> and, if no strategy has been
889 specified, <tt>-s recursive</tt>. Note the reversal of <em>ours</em> and
890 <em>theirs</em> as noted in above for the <tt>-m</tt> option.
891</p>
892</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59893<dt class="hdlist1">
Junio C Hamano2c14c8d2009-07-02 03:17:00894-q
895</dt>
Junio C Hamano68cf15a2010-11-06 01:01:59896<dt class="hdlist1">
Junio C Hamano2c14c8d2009-07-02 03:17:00897--quiet
898</dt>
899<dd>
900<p>
901 Be quiet. Implies --no-stat.
902</p>
903</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59904<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:47905-v
906</dt>
Junio C Hamano68cf15a2010-11-06 01:01:59907<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:47908--verbose
Junio C Hamanofbe00522006-10-19 05:58:48909</dt>
910<dd>
911<p>
Junio C Hamanoea6a7642009-03-11 23:56:19912 Be verbose. Implies --stat.
913</p>
914</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59915<dt class="hdlist1">
Junio C Hamanoea6a7642009-03-11 23:56:19916--stat
917</dt>
918<dd>
919<p>
920 Show a diffstat of what changed upstream since the last rebase. The
921 diffstat is also controlled by the configuration option rebase.stat.
922</p>
923</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59924<dt class="hdlist1">
Junio C Hamanoea6a7642009-03-11 23:56:19925-n
926</dt>
Junio C Hamano68cf15a2010-11-06 01:01:59927<dt class="hdlist1">
Junio C Hamanoea6a7642009-03-11 23:56:19928--no-stat
929</dt>
930<dd>
931<p>
932 Do not show a diffstat as part of the rebase process.
Junio C Hamanofbe00522006-10-19 05:58:48933</p>
934</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59935<dt class="hdlist1">
Junio C Hamano7d06a8a2008-10-20 05:42:33936--no-verify
937</dt>
938<dd>
939<p>
940 This option bypasses the pre-rebase hook. See also <a href="githooks.html">githooks(5)</a>.
941</p>
942</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59943<dt class="hdlist1">
Junio C Hamanoeef01fe2010-12-13 08:31:58944--verify
945</dt>
946<dd>
947<p>
948 Allows the pre-rebase hook to run, which is the default. This option can
949 be used to override --no-verify. See also <a href="githooks.html">githooks(5)</a>.
950</p>
951</dd>
952<dt class="hdlist1">
Junio C Hamanod3339982007-02-09 08:38:48953-C&lt;n&gt;
954</dt>
955<dd>
956<p>
957 Ensure at least &lt;n&gt; lines of surrounding context match before
958 and after each change. When fewer lines of surrounding
959 context exist they all must match. By default no context is
960 ever ignored.
961</p>
962</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59963<dt class="hdlist1">
Junio C Hamanoa973f1c2009-03-19 17:47:52964-f
965</dt>
Junio C Hamano68cf15a2010-11-06 01:01:59966<dt class="hdlist1">
Junio C Hamanoa973f1c2009-03-19 17:47:52967--force-rebase
968</dt>
969<dd>
970<p>
971 Force the rebase even if the current branch is a descendant
Junio C Hamanoef8fbf92010-04-04 19:12:02972 of the commit you are rebasing onto. Normally non-interactive rebase will
Junio C Hamanoa973f1c2009-03-19 17:47:52973 exit with the message "Current branch is up to date" in such a
974 situation.
Junio C Hamanoef8fbf92010-04-04 19:12:02975 Incompatible with the --interactive option.
Junio C Hamanoa973f1c2009-03-19 17:47:52976</p>
Junio C Hamano68cf15a2010-11-06 01:01:59977<div class="paragraph"><p>You may find this (or --no-ff with an interactive rebase) helpful after
Junio C Hamanoef8fbf92010-04-04 19:12:02978reverting a topic branch merge, as this option recreates the topic branch with
979fresh commits so it can be remerged successfully without needing to "revert
980the reversion" (see the
981<a href="howto/revert-a-faulty-merge.txt">revert-a-faulty-merge How-To</a> for details).</p></div>
Junio C Hamanoa973f1c2009-03-19 17:47:52982</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59983<dt class="hdlist1">
Junio C Hamanofe24db02009-08-22 05:10:47984--ignore-whitespace
985</dt>
Junio C Hamano68cf15a2010-11-06 01:01:59986<dt class="hdlist1">
Junio C Hamanof8a79222009-03-01 08:02:50987--whitespace=&lt;option&gt;
Junio C Hamano250f03e2007-09-10 01:33:28988</dt>
989<dd>
990<p>
Junio C Hamano1aa40d22010-01-21 17:46:43991 These flag are passed to the <em>git apply</em> program
Junio C Hamano250f03e2007-09-10 01:33:28992 (see <a href="git-apply.html">git-apply(1)</a>) that applies the patch.
Junio C Hamanoec3b9a72009-02-13 08:45:52993 Incompatible with the --interactive option.
Junio C Hamano250f03e2007-09-10 01:33:28994</p>
995</dd>
Junio C Hamano68cf15a2010-11-06 01:01:59996<dt class="hdlist1">
Junio C Hamanoa973f1c2009-03-19 17:47:52997--committer-date-is-author-date
998</dt>
Junio C Hamano68cf15a2010-11-06 01:01:59999<dt class="hdlist1">
Junio C Hamanoa973f1c2009-03-19 17:47:521000--ignore-date
1001</dt>
1002<dd>
1003<p>
Junio C Hamano1aa40d22010-01-21 17:46:431004 These flags are passed to <em>git am</em> to easily change the dates
Junio C Hamanoa973f1c2009-03-19 17:47:521005 of the rebased commits (see <a href="git-am.html">git-am(1)</a>).
Junio C Hamanoe97d5772010-05-19 08:13:581006 Incompatible with the --interactive option.
Junio C Hamanoa973f1c2009-03-19 17:47:521007</p>
1008</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591009<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:471010-i
1011</dt>
Junio C Hamano68cf15a2010-11-06 01:01:591012<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:471013--interactive
Junio C Hamano1d90cb02007-07-03 07:05:311014</dt>
1015<dd>
1016<p>
1017 Make a list of the commits which are about to be rebased. Let the
Junio C Hamanodbb64592007-09-01 11:17:391018 user edit that list before rebasing. This mode can also be used to
1019 split commits (see SPLITTING COMMITS below).
Junio C Hamano1d90cb02007-07-03 07:05:311020</p>
1021</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591022<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:471023-p
1024</dt>
Junio C Hamano68cf15a2010-11-06 01:01:591025<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:471026--preserve-merges
Junio C Hamano1d90cb02007-07-03 07:05:311027</dt>
1028<dd>
1029<p>
Junio C Hamano7d06a8a2008-10-20 05:42:331030 Instead of ignoring merges, try to recreate them.
Junio C Hamano1d90cb02007-07-03 07:05:311031</p>
Junio C Hamano68cf15a2010-11-06 01:01:591032<div class="paragraph"><p>This uses the <tt>--interactive</tt> machinery internally, but combining it
Junio C Hamanobb88cf42010-06-21 15:23:551033with the <tt>--interactive</tt> option explicitly is generally not a good
1034idea unless you know what you are doing (see BUGS below).</p></div>
Junio C Hamano1d90cb02007-07-03 07:05:311035</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591036<dt class="hdlist1">
Junio C Hamanobd53dbf2009-01-18 18:26:371037--root
1038</dt>
1039<dd>
1040<p>
1041 Rebase all commits reachable from &lt;branch&gt;, instead of
1042 limiting them with an &lt;upstream&gt;. This allows you to rebase
1043 the root commit(s) on a branch. Must be used with --onto, and
1044 will skip changes already contained in &lt;newbase&gt; (instead of
1045 &lt;upstream&gt;). When used together with --preserve-merges, <em>all</em>
1046 root commits will be rewritten to have &lt;newbase&gt; as parent
1047 instead.
1048</p>
1049</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591050<dt class="hdlist1">
Junio C Hamanoa9701f02010-01-21 00:42:161051--autosquash
1052</dt>
Junio C Hamano68cf15a2010-11-06 01:01:591053<dt class="hdlist1">
Junio C Hamano075ae872010-09-01 18:43:071054--no-autosquash
1055</dt>
Junio C Hamanoa9701f02010-01-21 00:42:161056<dd>
1057<p>
1058 When the commit log message begins with "squash! &#8230;" (or
1059 "fixup! &#8230;"), and there is a commit whose title begins with
1060 the same &#8230;, automatically modify the todo list of rebase -i
Junio C Hamano364b6a42010-01-22 07:57:591061 so that the commit marked for squashing comes right after the
Junio C Hamanoa9701f02010-01-21 00:42:161062 commit to be modified, and change the action of the moved
1063 commit from <tt>pick</tt> to <tt>squash</tt> (or <tt>fixup</tt>).
1064</p>
Junio C Hamano68cf15a2010-11-06 01:01:591065<div class="paragraph"><p>This option is only valid when the <em>--interactive</em> option is used.</p></div>
1066<div class="paragraph"><p>If the <em>--autosquash</em> option is enabled by default using the
Junio C Hamano075ae872010-09-01 18:43:071067configuration variable <tt>rebase.autosquash</tt>, this option can be
1068used to override and disable this setting.</p></div>
Junio C Hamanoef8fbf92010-04-04 19:12:021069</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591070<dt class="hdlist1">
Junio C Hamanoef8fbf92010-04-04 19:12:021071--no-ff
1072</dt>
1073<dd>
1074<p>
1075 With --interactive, cherry-pick all rebased commits instead of
1076 fast-forwarding over the unchanged ones. This ensures that the
1077 entire history of the rebased branch is composed of new commits.
1078</p>
Junio C Hamano68cf15a2010-11-06 01:01:591079<div class="paragraph"><p>Without --interactive, this is a synonym for --force-rebase.</p></div>
1080<div class="paragraph"><p>You may find this helpful after reverting a topic branch merge, as this option
Junio C Hamanoef8fbf92010-04-04 19:12:021081recreates the topic branch with fresh commits so it can be remerged
1082successfully without needing to "revert the reversion" (see the
1083<a href="howto/revert-a-faulty-merge.txt">revert-a-faulty-merge How-To</a> for details).</p></div>
Junio C Hamanoa9701f02010-01-21 00:42:161084</dd>
Junio C Hamanoba4b9282008-07-06 05:20:311085</dl></div>
Junio C Hamano97f518c2006-06-22 19:49:351086</div>
Junio C Hamanoba4b9282008-07-06 05:20:311087<h2 id="_merge_strategies">MERGE STRATEGIES</h2>
Junio C Hamano97f518c2006-06-22 19:49:351088<div class="sectionbody">
Junio C Hamano68cf15a2010-11-06 01:01:591089<div class="paragraph"><p>The merge mechanism (<em>git-merge</em> and <em>git-pull</em> commands) allows the
Junio C Hamano1aa40d22010-01-21 17:46:431090backend <em>merge strategies</em> to be chosen with <tt>-s</tt> option. Some strategies
1091can also take their own options, which can be passed by giving <tt>-X&lt;option&gt;</tt>
1092arguments to <em>git-merge</em> and/or <em>git-pull</em>.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591093<div class="dlist"><dl>
1094<dt class="hdlist1">
Junio C Hamano97f518c2006-06-22 19:49:351095resolve
1096</dt>
1097<dd>
1098<p>
1099 This can only resolve two heads (i.e. the current branch
Junio C Hamano1de75722009-03-26 08:39:381100 and another branch you pulled from) using a 3-way merge
Junio C Hamano97f518c2006-06-22 19:49:351101 algorithm. It tries to carefully detect criss-cross
1102 merge ambiguities and is considered generally safe and
1103 fast.
1104</p>
1105</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591106<dt class="hdlist1">
Junio C Hamano97f518c2006-06-22 19:49:351107recursive
1108</dt>
1109<dd>
1110<p>
Junio C Hamano1de75722009-03-26 08:39:381111 This can only resolve two heads using a 3-way merge
1112 algorithm. When there is more than one common
1113 ancestor that can be used for 3-way merge, it creates a
Junio C Hamano97f518c2006-06-22 19:49:351114 merged tree of the common ancestors and uses that as
1115 the reference tree for the 3-way merge. This has been
1116 reported to result in fewer merge conflicts without
1117 causing mis-merges by tests done on actual merge commits
1118 taken from Linux 2.6 kernel development history.
1119 Additionally this can detect and handle merges involving
1120 renames. This is the default merge strategy when
1121 pulling or merging one branch.
1122</p>
Junio C Hamano68cf15a2010-11-06 01:01:591123<div class="paragraph"><p>The <em>recursive</em> strategy can take the following options:</p></div>
1124<div class="dlist"><dl>
1125<dt class="hdlist1">
Junio C Hamano1aa40d22010-01-21 17:46:431126ours
1127</dt>
1128<dd>
1129<p>
1130 This option forces conflicting hunks to be auto-resolved cleanly by
1131 favoring <em>our</em> version. Changes from the other tree that do not
1132 conflict with our side are reflected to the merge result.
1133</p>
Junio C Hamano68cf15a2010-11-06 01:01:591134<div class="paragraph"><p>This should not be confused with the <em>ours</em> merge strategy, which does not
Junio C Hamano1aa40d22010-01-21 17:46:431135even look at what the other tree contains at all. It discards everything
1136the other tree did, declaring <em>our</em> history contains all that happened in it.</p></div>
1137</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591138<dt class="hdlist1">
Junio C Hamano1aa40d22010-01-21 17:46:431139theirs
1140</dt>
1141<dd>
1142<p>
1143 This is opposite of <em>ours</em>.
1144</p>
1145</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591146<dt class="hdlist1">
Junio C Hamano39c7a692010-10-27 06:08:541147patience
1148</dt>
1149<dd>
1150<p>
1151 With this option, <em>merge-recursive</em> spends a little extra time
1152 to avoid mismerges that sometimes occur due to unimportant
1153 matching lines (e.g., braces from distinct functions). Use
1154 this when the branches to be merged have diverged wildly.
1155 See also <a href="git-diff.html">git-diff(1)</a> <tt>--patience</tt>.
1156</p>
1157</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591158<dt class="hdlist1">
Junio C Hamano39c7a692010-10-27 06:08:541159ignore-space-change
1160</dt>
Junio C Hamano68cf15a2010-11-06 01:01:591161<dt class="hdlist1">
Junio C Hamano39c7a692010-10-27 06:08:541162ignore-all-space
1163</dt>
Junio C Hamano68cf15a2010-11-06 01:01:591164<dt class="hdlist1">
Junio C Hamano39c7a692010-10-27 06:08:541165ignore-space-at-eol
1166</dt>
1167<dd>
1168<p>
1169 Treats lines with the indicated type of whitespace change as
1170 unchanged for the sake of a three-way merge. Whitespace
1171 changes mixed with other changes to a line are not ignored.
1172 See also <a href="git-diff.html">git-diff(1)</a> <tt>-b</tt>, <tt>-w</tt>, and
1173 <tt>--ignore-space-at-eol</tt>.
1174</p>
Junio C Hamano68cf15a2010-11-06 01:01:591175<div class="ulist"><ul>
Junio C Hamano39c7a692010-10-27 06:08:541176<li>
1177<p>
1178If <em>their</em> version only introduces whitespace changes to a line,
1179 <em>our</em> version is used;
1180</p>
1181</li>
1182<li>
1183<p>
1184If <em>our</em> version introduces whitespace changes but <em>their</em>
1185 version includes a substantial change, <em>their</em> version is used;
1186</p>
1187</li>
1188<li>
1189<p>
1190Otherwise, the merge proceeds in the usual way.
1191</p>
1192</li>
1193</ul></div>
1194</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591195<dt class="hdlist1">
Junio C Hamano2db3e752010-09-03 21:33:061196renormalize
1197</dt>
1198<dd>
1199<p>
1200 This runs a virtual check-out and check-in of all three stages
1201 of a file when resolving a three-way merge. This option is
1202 meant to be used when merging branches with different clean
1203 filters or end-of-line normalization rules. See "Merging
1204 branches with differing checkin/checkout attributes" in
1205 <a href="gitattributes.html">gitattributes(5)</a> for details.
1206</p>
1207</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591208<dt class="hdlist1">
Junio C Hamano2db3e752010-09-03 21:33:061209no-renormalize
1210</dt>
1211<dd>
1212<p>
1213 Disables the <tt>renormalize</tt> option. This overrides the
1214 <tt>merge.renormalize</tt> configuration variable.
1215</p>
1216</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591217<dt class="hdlist1">
Junio C Hamano39c7a692010-10-27 06:08:541218rename-threshold=&lt;n&gt;
1219</dt>
1220<dd>
1221<p>
1222 Controls the similarity threshold used for rename detection.
1223 See also <a href="git-diff.html">git-diff(1)</a> <tt>-M</tt>.
1224</p>
1225</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591226<dt class="hdlist1">
Junio C Hamanod2179ef2010-10-22 04:12:171227subtree[=&lt;path&gt;]
Junio C Hamano1aa40d22010-01-21 17:46:431228</dt>
1229<dd>
1230<p>
1231 This option is a more advanced form of <em>subtree</em> strategy, where
1232 the strategy makes a guess on how two trees must be shifted to
1233 match with each other when merging. Instead, the specified path
1234 is prefixed (or stripped from the beginning) to make the shape of
1235 two trees to match.
1236</p>
1237</dd>
1238</dl></div>
Junio C Hamano97f518c2006-06-22 19:49:351239</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591240<dt class="hdlist1">
Junio C Hamano97f518c2006-06-22 19:49:351241octopus
1242</dt>
1243<dd>
1244<p>
Junio C Hamano1de75722009-03-26 08:39:381245 This resolves cases with more than two heads, but refuses to do
1246 a complex merge that needs manual resolution. It is
Junio C Hamano97f518c2006-06-22 19:49:351247 primarily meant to be used for bundling topic branch
1248 heads together. This is the default merge strategy when
Junio C Hamano1de75722009-03-26 08:39:381249 pulling or merging more than one branch.
Junio C Hamano97f518c2006-06-22 19:49:351250</p>
1251</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591252<dt class="hdlist1">
Junio C Hamano97f518c2006-06-22 19:49:351253ours
1254</dt>
1255<dd>
1256<p>
Junio C Hamanobf984de2009-11-23 06:11:191257 This resolves any number of heads, but the resulting tree of the
1258 merge is always that of the current branch head, effectively
1259 ignoring all changes from all other branches. It is meant to
Junio C Hamano97f518c2006-06-22 19:49:351260 be used to supersede old development history of side
Junio C Hamano1aa40d22010-01-21 17:46:431261 branches. Note that this is different from the -Xours option to
1262 the <em>recursive</em> merge strategy.
Junio C Hamano97f518c2006-06-22 19:49:351263</p>
1264</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591265<dt class="hdlist1">
Junio C Hamanoe6c92032008-03-19 09:24:341266subtree
1267</dt>
1268<dd>
1269<p>
1270 This is a modified recursive strategy. When merging trees A and
1271 B, if B corresponds to a subtree of A, B is first adjusted to
1272 match the tree structure of A, instead of reading the trees at
1273 the same level. This adjustment is also done to the common
1274 ancestor tree.
1275</p>
1276</dd>
Junio C Hamanoba4b9282008-07-06 05:20:311277</dl></div>
Junio C Hamano1a4e8412005-12-27 08:17:231278</div>
Junio C Hamanoba4b9282008-07-06 05:20:311279<h2 id="_notes">NOTES</h2>
Junio C Hamano6112cad2006-05-02 07:28:061280<div class="sectionbody">
Junio C Hamano68cf15a2010-11-06 01:01:591281<div class="paragraph"><p>You should understand the implications of using <em>git rebase</em> on a
Junio C Hamano7d06a8a2008-10-20 05:42:331282repository that you share. See also RECOVERING FROM UPSTREAM REBASE
1283below.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591284<div class="paragraph"><p>When the git-rebase command is run, it will first execute a "pre-rebase"
Junio C Hamano6112cad2006-05-02 07:28:061285hook if one exists. You can use this hook to do sanity checks and
Junio C Hamano68cf15a2010-11-06 01:01:591286reject the rebase if it isn&#8217;t appropriate. Please see the template
Junio C Hamanoba4b9282008-07-06 05:20:311287pre-rebase hook script for an example.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591288<div class="paragraph"><p>Upon completion, &lt;branch&gt; will be the current branch.</p></div>
Junio C Hamano6112cad2006-05-02 07:28:061289</div>
Junio C Hamanoba4b9282008-07-06 05:20:311290<h2 id="_interactive_mode">INTERACTIVE MODE</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231291<div class="sectionbody">
Junio C Hamano68cf15a2010-11-06 01:01:591292<div class="paragraph"><p>Rebasing interactively means that you have a chance to edit the commits
Junio C Hamano1d90cb02007-07-03 07:05:311293which are rebased. You can reorder the commits, and you can
Junio C Hamanoba4b9282008-07-06 05:20:311294remove them (weeding out bad or otherwise unwanted patches).</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591295<div class="paragraph"><p>The interactive mode is meant for this type of workflow:</p></div>
1296<div class="olist arabic"><ol class="arabic">
Junio C Hamano1d90cb02007-07-03 07:05:311297<li>
1298<p>
1299have a wonderful idea
1300</p>
1301</li>
1302<li>
1303<p>
1304hack on the code
1305</p>
1306</li>
1307<li>
1308<p>
1309prepare a series for submission
1310</p>
1311</li>
1312<li>
1313<p>
1314submit
1315</p>
1316</li>
Junio C Hamanoba4b9282008-07-06 05:20:311317</ol></div>
Junio C Hamano68cf15a2010-11-06 01:01:591318<div class="paragraph"><p>where point 2. consists of several instances of</p></div>
1319<div class="olist loweralpha"><ol class="loweralpha">
Junio C Hamano1d90cb02007-07-03 07:05:311320<li>
1321<p>
1322regular use
1323</p>
Junio C Hamano68cf15a2010-11-06 01:01:591324<div class="olist arabic"><ol class="arabic">
Junio C Hamano1d90cb02007-07-03 07:05:311325<li>
1326<p>
1327finish something worthy of a commit
1328</p>
1329</li>
1330<li>
1331<p>
1332commit
1333</p>
1334</li>
Junio C Hamanoba4b9282008-07-06 05:20:311335</ol></div>
Junio C Hamano1d90cb02007-07-03 07:05:311336</li>
1337<li>
1338<p>
1339independent fixup
1340</p>
Junio C Hamano68cf15a2010-11-06 01:01:591341<div class="olist arabic"><ol class="arabic">
Junio C Hamano1d90cb02007-07-03 07:05:311342<li>
1343<p>
1344realize that something does not work
1345</p>
1346</li>
1347<li>
1348<p>
1349fix that
1350</p>
1351</li>
1352<li>
1353<p>
1354commit it
1355</p>
1356</li>
Junio C Hamanoba4b9282008-07-06 05:20:311357</ol></div>
Junio C Hamano1d90cb02007-07-03 07:05:311358</li>
Junio C Hamanoba4b9282008-07-06 05:20:311359</ol></div>
Junio C Hamano68cf15a2010-11-06 01:01:591360<div class="paragraph"><p>Sometimes the thing fixed in b.2. cannot be amended to the not-quite
Junio C Hamano1d90cb02007-07-03 07:05:311361perfect commit it fixes, because that commit is buried deeply in a
1362patch series. That is exactly what interactive rebase is for: use it
1363after plenty of "a"s and "b"s, by rearranging and editing
Junio C Hamanoba4b9282008-07-06 05:20:311364commits, and squashing multiple commits into one.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591365<div class="paragraph"><p>Start it with the last commit you want to retain as-is:</p></div>
Junio C Hamano1d90cb02007-07-03 07:05:311366<div class="literalblock">
1367<div class="content">
1368<pre><tt>git rebase -i &lt;after-this-commit&gt;</tt></pre>
1369</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591370<div class="paragraph"><p>An editor will be fired up with all the commits in your current branch
Junio C Hamano1d90cb02007-07-03 07:05:311371(ignoring merge commits), which come after the given commit. You can
Junio C Hamano68cf15a2010-11-06 01:01:591372reorder the commits in this list to your heart&#8217;s content, and you can
Junio C Hamanoba4b9282008-07-06 05:20:311373remove them. The list looks more or less like this:</p></div>
Junio C Hamano1d90cb02007-07-03 07:05:311374<div class="listingblock">
1375<div class="content">
1376<pre><tt>pick deadbee The oneline of this commit
1377pick fa1afe1 The oneline of the next commit
1378...</tt></pre>
1379</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591380<div class="paragraph"><p>The oneline descriptions are purely for your pleasure; <em>git rebase</em> will
Junio C Hamano1d90cb02007-07-03 07:05:311381not look at them but at the commit names ("deadbee" and "fa1afe1" in this
Junio C Hamanoba4b9282008-07-06 05:20:311382example), so do not delete or edit the names.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591383<div class="paragraph"><p>By replacing the command "pick" with the command "edit", you can tell
Junio C Hamano1aa40d22010-01-21 17:46:431384<em>git rebase</em> to stop after applying that commit, so that you can edit
Junio C Hamano1d90cb02007-07-03 07:05:311385the files and/or the commit message, amend the commit, and continue
Junio C Hamanoba4b9282008-07-06 05:20:311386rebasing.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591387<div class="paragraph"><p>If you just want to edit the commit message for a commit, replace the
Junio C Hamano3d23a0a2009-10-19 08:04:301388command "pick" with the command "reword".</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591389<div class="paragraph"><p>If you want to fold two or more commits into one, replace the command
Junio C Hamanoa9701f02010-01-21 00:42:161390"pick" for the second and subsequent commits with "squash" or "fixup".
1391If the commits had different authors, the folded commit will be
1392attributed to the author of the first commit. The suggested commit
1393message for the folded commit is the concatenation of the commit
1394messages of the first commit and of those with the "squash" command,
1395but omits the commit messages of commits with the "fixup" command.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591396<div class="paragraph"><p><em>git rebase</em> will stop when "pick" has been replaced with "edit" or
Junio C Hamano3d23a0a2009-10-19 08:04:301397when a command fails due to merge errors. When you are done editing
1398and/or resolving conflicts you can continue with <tt>git rebase --continue</tt>.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591399<div class="paragraph"><p>For example, if you want to reorder the last 5 commits, such that what
Junio C Hamano1d90cb02007-07-03 07:05:311400was HEAD~4 becomes the new HEAD. To achieve that, you would call
Junio C Hamano1aa40d22010-01-21 17:46:431401<em>git rebase</em> like this:</p></div>
Junio C Hamano1d90cb02007-07-03 07:05:311402<div class="listingblock">
1403<div class="content">
1404<pre><tt>$ git rebase -i HEAD~5</tt></pre>
1405</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591406<div class="paragraph"><p>And move the first patch to the end of the list.</p></div>
1407<div class="paragraph"><p>You might want to preserve merges, if you have a history like this:</p></div>
Junio C Hamano1d90cb02007-07-03 07:05:311408<div class="listingblock">
1409<div class="content">
1410<pre><tt> X
1411 \
1412 A---M---B
1413 /
1414---o---O---P---Q</tt></pre>
1415</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591416<div class="paragraph"><p>Suppose you want to rebase the side branch starting at "A" to "Q". Make
Junio C Hamanoba4b9282008-07-06 05:20:311417sure that the current HEAD is "B", and call</p></div>
Junio C Hamano1d90cb02007-07-03 07:05:311418<div class="listingblock">
1419<div class="content">
1420<pre><tt>$ git rebase -i -p --onto Q O</tt></pre>
1421</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591422<div class="paragraph"><p>Reordering and editing commits usually creates untested intermediate
Junio C Hamano53ba6d02010-08-22 07:25:121423steps. You may want to check that your history editing did not break
1424anything by running a test, or at least recompiling at intermediate
1425points in history by using the "exec" command (shortcut "x"). You may
1426do so by creating a todo list like this one:</p></div>
1427<div class="listingblock">
1428<div class="content">
1429<pre><tt>pick deadbee Implement feature XXX
1430fixup f1a5c00 Fix to feature XXX
1431exec make
1432pick c0ffeee The oneline of the next commit
1433edit deadbab The oneline of the commit after
1434exec cd subdir; make test
1435...</tt></pre>
1436</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591437<div class="paragraph"><p>The interactive rebase will stop when a command fails (i.e. exits with
Junio C Hamano53ba6d02010-08-22 07:25:121438non-0 status) to give you an opportunity to fix the problem. You can
1439continue with <tt>git rebase --continue</tt>.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591440<div class="paragraph"><p>The "exec" command launches the command in a shell (the one specified
Junio C Hamano53ba6d02010-08-22 07:25:121441in <tt>$SHELL</tt>, or the default shell if <tt>$SHELL</tt> is not set), so you can
1442use shell features (like "cd", "&gt;", ";" &#8230;). The command is run from
1443the root of the working tree.</p></div>
Junio C Hamano1d90cb02007-07-03 07:05:311444</div>
Junio C Hamanoba4b9282008-07-06 05:20:311445<h2 id="_splitting_commits">SPLITTING COMMITS</h2>
Junio C Hamanodbb64592007-09-01 11:17:391446<div class="sectionbody">
Junio C Hamano68cf15a2010-11-06 01:01:591447<div class="paragraph"><p>In interactive mode, you can mark commits with the action "edit". However,
Junio C Hamano1aa40d22010-01-21 17:46:431448this does not necessarily mean that <em>git rebase</em> expects the result of this
Junio C Hamanodbb64592007-09-01 11:17:391449edit to be exactly one commit. Indeed, you can undo the commit, or you can
Junio C Hamanoba4b9282008-07-06 05:20:311450add other commits. This can be used to split a commit into two:</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591451<div class="ulist"><ul>
Junio C Hamanodbb64592007-09-01 11:17:391452<li>
1453<p>
Junio C Hamanofce7c7e2008-07-02 03:06:381454Start an interactive rebase with <tt>git rebase -i &lt;commit&gt;^</tt>, where
Junio C Hamanodbb64592007-09-01 11:17:391455 &lt;commit&gt; is the commit you want to split. In fact, any commit range
1456 will do, as long as it contains that commit.
1457</p>
1458</li>
1459<li>
1460<p>
1461Mark the commit you want to split with the action "edit".
1462</p>
1463</li>
1464<li>
1465<p>
Junio C Hamanofce7c7e2008-07-02 03:06:381466When it comes to editing that commit, execute <tt>git reset HEAD^</tt>. The
Junio C Hamanodbb64592007-09-01 11:17:391467 effect is that the HEAD is rewound by one, and the index follows suit.
1468 However, the working tree stays the same.
1469</p>
1470</li>
1471<li>
1472<p>
1473Now add the changes to the index that you want to have in the first
Junio C Hamanofce7c7e2008-07-02 03:06:381474 commit. You can use <tt>git add</tt> (possibly interactively) or
Junio C Hamano1aa40d22010-01-21 17:46:431475 <em>git gui</em> (or both) to do that.
Junio C Hamanodbb64592007-09-01 11:17:391476</p>
1477</li>
1478<li>
1479<p>
1480Commit the now-current index with whatever commit message is appropriate
1481 now.
1482</p>
1483</li>
1484<li>
1485<p>
1486Repeat the last two steps until your working tree is clean.
1487</p>
1488</li>
1489<li>
1490<p>
Junio C Hamanofce7c7e2008-07-02 03:06:381491Continue the rebase with <tt>git rebase --continue</tt>.
Junio C Hamanodbb64592007-09-01 11:17:391492</p>
1493</li>
Junio C Hamanoba4b9282008-07-06 05:20:311494</ul></div>
Junio C Hamano68cf15a2010-11-06 01:01:591495<div class="paragraph"><p>If you are not absolutely sure that the intermediate revisions are
Junio C Hamanodbb64592007-09-01 11:17:391496consistent (they compile, pass the testsuite, etc.) you should use
Junio C Hamano1aa40d22010-01-21 17:46:431497<em>git stash</em> to stash away the not-yet-committed changes
Junio C Hamanoba4b9282008-07-06 05:20:311498after each commit, test, and amend the commit if fixes are necessary.</p></div>
Junio C Hamanodbb64592007-09-01 11:17:391499</div>
Junio C Hamano7d06a8a2008-10-20 05:42:331500<h2 id="_recovering_from_upstream_rebase">RECOVERING FROM UPSTREAM REBASE</h2>
1501<div class="sectionbody">
Junio C Hamano68cf15a2010-11-06 01:01:591502<div class="paragraph"><p>Rebasing (or any other form of rewriting) a branch that others have
Junio C Hamano7d06a8a2008-10-20 05:42:331503based work on is a bad idea: anyone downstream of it is forced to
1504manually fix their history. This section explains how to do the fix
Junio C Hamano68cf15a2010-11-06 01:01:591505from the downstream&#8217;s point of view. The real fix, however, would be
Junio C Hamano7d06a8a2008-10-20 05:42:331506to avoid rebasing the upstream in the first place.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591507<div class="paragraph"><p>To illustrate, suppose you are in a situation where someone develops a
Junio C Hamano7d06a8a2008-10-20 05:42:331508<em>subsystem</em> branch, and you are working on a <em>topic</em> that is dependent
1509on this <em>subsystem</em>. You might end up with a history like the
1510following:</p></div>
1511<div class="listingblock">
1512<div class="content">
1513<pre><tt> o---o---o---o---o---o---o---o---o master
1514 \
1515 o---o---o---o---o subsystem
1516 \
1517 *---*---* topic</tt></pre>
1518</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591519<div class="paragraph"><p>If <em>subsystem</em> is rebased against <em>master</em>, the following happens:</p></div>
Junio C Hamano7d06a8a2008-10-20 05:42:331520<div class="listingblock">
1521<div class="content">
1522<pre><tt> o---o---o---o---o---o---o---o master
1523 \ \
1524 o---o---o---o---o o'--o'--o'--o'--o' subsystem
1525 \
1526 *---*---* topic</tt></pre>
1527</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591528<div class="paragraph"><p>If you now continue development as usual, and eventually merge <em>topic</em>
Junio C Hamano7d06a8a2008-10-20 05:42:331529to <em>subsystem</em>, the commits from <em>subsystem</em> will remain duplicated forever:</p></div>
1530<div class="listingblock">
1531<div class="content">
1532<pre><tt> o---o---o---o---o---o---o---o master
1533 \ \
1534 o---o---o---o---o o'--o'--o'--o'--o'--M subsystem
1535 \ /
1536 *---*---*-..........-*--* topic</tt></pre>
1537</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591538<div class="paragraph"><p>Such duplicates are generally frowned upon because they clutter up
Junio C Hamano7d06a8a2008-10-20 05:42:331539history, making it harder to follow. To clean things up, you need to
1540transplant the commits on <em>topic</em> to the new <em>subsystem</em> tip, i.e.,
1541rebase <em>topic</em>. This becomes a ripple effect: anyone downstream from
1542<em>topic</em> is forced to rebase too, and so on!</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591543<div class="paragraph"><p>There are two kinds of fixes, discussed in the following subsections:</p></div>
1544<div class="dlist"><dl>
1545<dt class="hdlist1">
Junio C Hamano7d06a8a2008-10-20 05:42:331546Easy case: The changes are literally the same.
1547</dt>
1548<dd>
1549<p>
1550 This happens if the <em>subsystem</em> rebase was a simple rebase and
1551 had no conflicts.
1552</p>
1553</dd>
Junio C Hamano68cf15a2010-11-06 01:01:591554<dt class="hdlist1">
Junio C Hamano7d06a8a2008-10-20 05:42:331555Hard case: The changes are not the same.
1556</dt>
1557<dd>
1558<p>
1559 This happens if the <em>subsystem</em> rebase had conflicts, or used
Junio C Hamanoa9701f02010-01-21 00:42:161560 <tt>--interactive</tt> to omit, edit, squash, or fixup commits; or
1561 if the upstream used one of <tt>commit --amend</tt>, <tt>reset</tt>, or
Junio C Hamano7d06a8a2008-10-20 05:42:331562 <tt>filter-branch</tt>.
1563</p>
1564</dd>
1565</dl></div>
1566<h3 id="_the_easy_case">The easy case</h3><div style="clear:left"></div>
Junio C Hamano68cf15a2010-11-06 01:01:591567<div class="paragraph"><p>Only works if the changes (patch IDs based on the diff contents) on
Junio C Hamano7d06a8a2008-10-20 05:42:331568<em>subsystem</em> are literally the same before and after the rebase
1569<em>subsystem</em> did.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591570<div class="paragraph"><p>In that case, the fix is easy because <em>git rebase</em> knows to skip
Junio C Hamano7d06a8a2008-10-20 05:42:331571changes that are already present in the new upstream. So if you say
Junio C Hamano68cf15a2010-11-06 01:01:591572(assuming you&#8217;re on <em>topic</em>)</p></div>
Junio C Hamano7d06a8a2008-10-20 05:42:331573<div class="listingblock">
1574<div class="content">
1575<pre><tt> $ git rebase subsystem</tt></pre>
1576</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591577<div class="paragraph"><p>you will end up with the fixed history</p></div>
Junio C Hamano7d06a8a2008-10-20 05:42:331578<div class="listingblock">
1579<div class="content">
1580<pre><tt> o---o---o---o---o---o---o---o master
1581 \
1582 o'--o'--o'--o'--o' subsystem
1583 \
1584 *---*---* topic</tt></pre>
1585</div></div>
1586<h3 id="_the_hard_case">The hard case</h3><div style="clear:left"></div>
Junio C Hamano68cf15a2010-11-06 01:01:591587<div class="paragraph"><p>Things get more complicated if the <em>subsystem</em> changes do not exactly
Junio C Hamano7d06a8a2008-10-20 05:42:331588correspond to the ones before the rebase.</p></div>
1589<div class="admonitionblock">
1590<table><tr>
1591<td class="icon">
1592<div class="title">Note</div>
1593</td>
1594<td class="content">While an "easy case recovery" sometimes appears to be successful
1595 even in the hard case, it may have unintended consequences. For
1596 example, a commit that was removed via <tt>git rebase
Junio C Hamano68cf15a2010-11-06 01:01:591597 --interactive</tt> will be <strong>resurrected</strong>!</td>
Junio C Hamano7d06a8a2008-10-20 05:42:331598</tr></table>
1599</div>
Junio C Hamano68cf15a2010-11-06 01:01:591600<div class="paragraph"><p>The idea is to manually tell <em>git rebase</em> "where the old <em>subsystem</em>
Junio C Hamano7d06a8a2008-10-20 05:42:331601ended and your <em>topic</em> began", that is, what the old merge-base
1602between them was. You will have to find a way to name the last commit
1603of the old <em>subsystem</em>, for example:</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591604<div class="ulist"><ul>
Junio C Hamano7d06a8a2008-10-20 05:42:331605<li>
1606<p>
Junio C Hamano1aa40d22010-01-21 17:46:431607With the <em>subsystem</em> reflog: after <em>git fetch</em>, the old tip of
Junio C Hamano7d06a8a2008-10-20 05:42:331608 <em>subsystem</em> is at <tt>subsystem@{1}</tt>. Subsequent fetches will
1609 increase the number. (See <a href="git-reflog.html">git-reflog(1)</a>.)
1610</p>
1611</li>
1612<li>
1613<p>
1614Relative to the tip of <em>topic</em>: knowing that your <em>topic</em> has three
1615 commits, the old tip of <em>subsystem</em> must be <tt>topic~3</tt>.
1616</p>
1617</li>
1618</ul></div>
Junio C Hamano68cf15a2010-11-06 01:01:591619<div class="paragraph"><p>You can then transplant the old <tt>subsystem..topic</tt> to the new tip by
Junio C Hamano7d06a8a2008-10-20 05:42:331620saying (for the reflog case, and assuming you are on <em>topic</em> already):</p></div>
1621<div class="listingblock">
1622<div class="content">
1623<pre><tt> $ git rebase --onto subsystem subsystem@{1}</tt></pre>
1624</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591625<div class="paragraph"><p>The ripple effect of a "hard case" recovery is especially bad:
Junio C Hamano7d06a8a2008-10-20 05:42:331626<em>everyone</em> downstream from <em>topic</em> will now have to perform a "hard
1627case" recovery too!</p></div>
1628</div>
Junio C Hamanobb88cf42010-06-21 15:23:551629<h2 id="_bugs">BUGS</h2>
1630<div class="sectionbody">
Junio C Hamano68cf15a2010-11-06 01:01:591631<div class="paragraph"><p>The todo list presented by <tt>--preserve-merges --interactive</tt> does not
Junio C Hamanobb88cf42010-06-21 15:23:551632represent the topology of the revision graph. Editing commits and
1633rewording their commit messages should work fine, but attempts to
1634reorder commits tend to produce counterintuitive results.</p></div>
Junio C Hamano68cf15a2010-11-06 01:01:591635<div class="paragraph"><p>For example, an attempt to rearrange</p></div>
Junio C Hamanobb88cf42010-06-21 15:23:551636<div class="listingblock">
1637<div class="content">
1638<pre><tt>1 --- 2 --- 3 --- 4 --- 5</tt></pre>
1639</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591640<div class="paragraph"><p>to</p></div>
Junio C Hamanobb88cf42010-06-21 15:23:551641<div class="listingblock">
1642<div class="content">
1643<pre><tt>1 --- 2 --- 4 --- 3 --- 5</tt></pre>
1644</div></div>
Junio C Hamano68cf15a2010-11-06 01:01:591645<div class="paragraph"><p>by moving the "pick 4" line will result in the following history:</p></div>
Junio C Hamanobb88cf42010-06-21 15:23:551646<div class="listingblock">
1647<div class="content">
1648<pre><tt> 3
1649 /
16501 --- 2 --- 4 --- 5</tt></pre>
1651</div></div>
1652</div>
Junio C Hamanoba4b9282008-07-06 05:20:311653<h2 id="_git">GIT</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231654<div class="sectionbody">
Junio C Hamano68cf15a2010-11-06 01:01:591655<div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231656</div>
Junio C Hamano7bd050f2011-09-22 06:32:221657</div>
1658<div id="footnotes"><hr /></div>
Junio C Hamano1a4e8412005-12-27 08:17:231659<div id="footer">
1660<div id="footer-text">
Junio C Hamano02194af2011-11-17 20:33:591661Last updated 2011-11-15 13:45:02 PDT
Junio C Hamano1a4e8412005-12-27 08:17:231662</div>
1663</div>
1664</body>
1665</html>