table example
[git/mjg.git] / Documentation / git-read-tree.html
blobdab6836f89464e892599a0dff7e0533c897aa41a
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" />
6 <meta name="generator" content="AsciiDoc 8.4.5" />
7 <title>git-read-tree(1)</title>
8 <style type="text/css">
9 /* Debug borders */
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
12 border: 1px solid red;
16 body {
17 margin: 1em 5% 1em 5%;
20 a {
21 color: blue;
22 text-decoration: underline;
24 a:visited {
25 color: fuchsia;
28 em {
29 font-style: italic;
30 color: navy;
33 strong {
34 font-weight: bold;
35 color: #083194;
38 tt {
39 color: navy;
42 h1, 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;
50 h1, h2, h3 {
51 border-bottom: 2px solid silver;
53 h2 {
54 padding-top: 0.5em;
56 h3 {
57 float: left;
59 h3 + * {
60 clear: left;
63 div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
68 hr {
69 border: 1px solid silver;
72 p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
77 ul, ol, li > p {
78 margin-top: 0;
81 pre {
82 padding: 0;
83 margin: 0;
86 span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
90 font-size: 1.1em;
92 span#email {
94 span#revnumber, span#revdate, span#revremark {
95 font-family: sans-serif;
98 div#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;
105 div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
109 div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
114 div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
118 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120 div.admonitionblock {
121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
124 div.admonitionblock {
125 margin-top: 2.5em;
126 margin-bottom: 2.5em;
129 div.content { /* Block element content. */
130 padding: 0;
133 /* Block element titles. */
134 div.title, caption.title {
135 color: #527bbd;
136 font-family: sans-serif;
137 font-weight: bold;
138 text-align: left;
139 margin-top: 1.0em;
140 margin-bottom: 0.5em;
142 div.title + * {
143 margin-top: 0;
146 td div.title:first-child {
147 margin-top: 0.0em;
149 div.content div.title:first-child {
150 margin-top: 0.0em;
152 div.content + div.title {
153 margin-top: 0.0em;
156 div.sidebarblock > div.content {
157 background: #ffffee;
158 border: 1px solid silver;
159 padding: 0.5em;
162 div.listingblock > div.content {
163 border: 1px solid silver;
164 background: #f4f4f4;
165 padding: 0.5em;
168 div.quoteblock {
169 padding-left: 2.0em;
170 margin-right: 10%;
172 div.quoteblock > div.attribution {
173 padding-top: 0.5em;
174 text-align: right;
177 div.verseblock {
178 padding-left: 2.0em;
179 margin-right: 10%;
181 div.verseblock > div.content {
182 white-space: pre;
184 div.verseblock > div.attribution {
185 padding-top: 0.75em;
186 text-align: left;
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div.verseblock + div.attribution {
190 text-align: left;
193 div.admonitionblock .icon {
194 vertical-align: top;
195 font-size: 1.1em;
196 font-weight: bold;
197 text-decoration: underline;
198 color: #527bbd;
199 padding-right: 0.5em;
201 div.admonitionblock td.content {
202 padding-left: 0.5em;
203 border-left: 2px solid silver;
206 div.exampleblock > div.content {
207 border-left: 2px solid silver;
208 padding: 0.5em;
211 div.imageblock div.content { padding-left: 0; }
212 span.image img { border-style: none; }
213 a.image:visited { color: white; }
215 dl {
216 margin-top: 0.8em;
217 margin-bottom: 0.8em;
219 dt {
220 margin-top: 0.5em;
221 margin-bottom: 0;
222 font-style: normal;
223 color: navy;
225 dd > *:first-child {
226 margin-top: 0.1em;
229 ul, ol {
230 list-style-position: outside;
232 ol.arabic {
233 list-style-type: decimal;
235 ol.loweralpha {
236 list-style-type: lower-alpha;
238 ol.upperalpha {
239 list-style-type: upper-alpha;
241 ol.lowerroman {
242 list-style-type: lower-roman;
244 ol.upperroman {
245 list-style-type: upper-roman;
248 div.compact ul, div.compact ol,
249 div.compact p, div.compact p,
250 div.compact div, div.compact div {
251 margin-top: 0.1em;
252 margin-bottom: 0.1em;
255 div.tableblock > table {
256 border: 3px solid #527bbd;
258 thead {
259 font-family: sans-serif;
260 font-weight: bold;
262 tfoot {
263 font-weight: bold;
265 td > div.verse {
266 white-space: pre;
268 p.table {
269 margin-top: 0;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div.tableblock > table[frame="void"] {
273 border-style: none;
275 div.tableblock > table[frame="hsides"] {
276 border-left-style: none;
277 border-right-style: none;
279 div.tableblock > table[frame="vsides"] {
280 border-top-style: none;
281 border-bottom-style: none;
285 div.hdlist {
286 margin-top: 0.8em;
287 margin-bottom: 0.8em;
289 div.hdlist tr {
290 padding-bottom: 15px;
292 dt.hdlist1.strong, td.hdlist1.strong {
293 font-weight: bold;
295 td.hdlist1 {
296 vertical-align: top;
297 font-style: normal;
298 padding-right: 0.8em;
299 color: navy;
301 td.hdlist2 {
302 vertical-align: top;
304 div.hdlist.compact tr {
305 margin: 0;
306 padding-bottom: 0;
309 .comment {
310 background: yellow;
313 @media print {
314 div#footer-badges { display: none; }
317 div#toctitle {
318 color: #527bbd;
319 font-family: sans-serif;
320 font-size: 1.1em;
321 font-weight: bold;
322 margin-top: 1.0em;
323 margin-bottom: 0.1em;
326 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
327 margin-top: 0;
328 margin-bottom: 0;
330 div.toclevel2 {
331 margin-left: 2em;
332 font-size: 0.9em;
334 div.toclevel3 {
335 margin-left: 4em;
336 font-size: 0.9em;
338 div.toclevel4 {
339 margin-left: 6em;
340 font-size: 0.9em;
342 /* Overrides for manpage documents */
343 h1 {
344 padding-top: 0.5em;
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver;
347 border-bottom: 2px solid silver;
349 h2 {
350 border-style: none;
352 div.sectionbody {
353 margin-left: 5%;
356 @media print {
357 div#toc { display: none; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div.sidebar-content {
363 background: #ffffee;
364 border: 1px solid silver;
365 padding: 0.5em;
367 div.sidebar-title, div.image-title {
368 color: #527bbd;
369 font-family: sans-serif;
370 font-weight: bold;
371 margin-top: 0.0em;
372 margin-bottom: 0.5em;
375 div.listingblock div.content {
376 border: 1px solid silver;
377 background: #f4f4f4;
378 padding: 0.5em;
381 div.quoteblock-attribution {
382 padding-top: 0.5em;
383 text-align: right;
386 div.verseblock-content {
387 white-space: pre;
389 div.verseblock-attribution {
390 padding-top: 0.75em;
391 text-align: left;
394 div.exampleblock-content {
395 border-left: 2px solid silver;
396 padding-left: 0.5em;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc a:visited { color: blue; }
401 </style>
402 </head>
403 <body>
404 <div id="header">
405 <h1>
406 git-read-tree(1) Manual Page
407 </h1>
408 <h2>NAME</h2>
409 <div class="sectionbody">
410 <p>git-read-tree -
411 Reads tree information into the index
412 </p>
413 </div>
414 </div>
415 <h2 id="_synopsis">SYNOPSIS</h2>
416 <div class="sectionbody">
417 <div class="paragraph"><p><em>git read-tree</em> [[-m [--trivial] [--aggressive] | --reset | --prefix=&lt;prefix&gt;]
418 [-u [--exclude-per-directory=&lt;gitignore&gt;] | -i]]
419 [--index-output=&lt;file&gt;] [--no-sparse-checkout]
420 &lt;tree-ish1&gt; [&lt;tree-ish2&gt; [&lt;tree-ish3&gt;]]</p></div>
421 </div>
422 <h2 id="_description">DESCRIPTION</h2>
423 <div class="sectionbody">
424 <div class="paragraph"><p>Reads the tree information given by &lt;tree-ish&gt; into the index,
425 but does not actually <strong>update</strong> any of the files it "caches". (see:
426 <a href="git-checkout-index.html">git-checkout-index(1)</a>)</p></div>
427 <div class="paragraph"><p>Optionally, it can merge a tree into the index, perform a
428 fast-forward (i.e. 2-way) merge, or a 3-way merge, with the <tt>-m</tt>
429 flag. When used with <tt>-m</tt>, the <tt>-u</tt> flag causes it to also update
430 the files in the work tree with the result of the merge.</p></div>
431 <div class="paragraph"><p>Trivial merges are done by <em>git read-tree</em> itself. Only conflicting paths
432 will be in unmerged state when <em>git read-tree</em> returns.</p></div>
433 </div>
434 <h2 id="_options">OPTIONS</h2>
435 <div class="sectionbody">
436 <div class="dlist"><dl>
437 <dt class="hdlist1">
439 </dt>
440 <dd>
442 Perform a merge, not just a read. The command will
443 refuse to run if your index file has unmerged entries,
444 indicating that you have not finished previous merge you
445 started.
446 </p>
447 </dd>
448 <dt class="hdlist1">
449 --reset
450 </dt>
451 <dd>
453 Same as -m, except that unmerged entries are discarded
454 instead of failing.
455 </p>
456 </dd>
457 <dt class="hdlist1">
459 </dt>
460 <dd>
462 After a successful merge, update the files in the work
463 tree with the result of the merge.
464 </p>
465 </dd>
466 <dt class="hdlist1">
468 </dt>
469 <dd>
471 Usually a merge requires the index file as well as the
472 files in the working tree are up to date with the
473 current head commit, in order not to lose local
474 changes. This flag disables the check with the working
475 tree and is meant to be used when creating a merge of
476 trees that are not directly related to the current
477 working tree status into a temporary index file.
478 </p>
479 </dd>
480 <dt class="hdlist1">
482 </dt>
483 <dd>
485 Show the progress of checking files out.
486 </p>
487 </dd>
488 <dt class="hdlist1">
489 --trivial
490 </dt>
491 <dd>
493 Restrict three-way merge by <em>git read-tree</em> to happen
494 only if there is no file-level merging required, instead
495 of resolving merge for trivial cases and leaving
496 conflicting files unresolved in the index.
497 </p>
498 </dd>
499 <dt class="hdlist1">
500 --aggressive
501 </dt>
502 <dd>
504 Usually a three-way merge by <em>git read-tree</em> resolves
505 the merge for really trivial cases and leaves other
506 cases unresolved in the index, so that Porcelains can
507 implement different merge policies. This flag makes the
508 command to resolve a few more cases internally:
509 </p>
510 <div class="ulist"><ul>
511 <li>
513 when one side removes a path and the other side leaves the path
514 unmodified. The resolution is to remove that path.
515 </p>
516 </li>
517 <li>
519 when both sides remove a path. The resolution is to remove that path.
520 </p>
521 </li>
522 <li>
524 when both sides adds a path identically. The resolution
525 is to add that path.
526 </p>
527 </li>
528 </ul></div>
529 </dd>
530 <dt class="hdlist1">
531 --prefix=&lt;prefix&gt;/
532 </dt>
533 <dd>
535 Keep the current index contents, and read the contents
536 of named tree-ish under directory at <tt>&lt;prefix&gt;</tt>. The
537 original index file cannot have anything at the path
538 <tt>&lt;prefix&gt;</tt> itself, and have nothing in <tt>&lt;prefix&gt;/</tt>
539 directory. Note that the <tt>&lt;prefix&gt;/</tt> value must end
540 with a slash.
541 </p>
542 </dd>
543 <dt class="hdlist1">
544 --exclude-per-directory=&lt;gitignore&gt;
545 </dt>
546 <dd>
548 When running the command with <tt>-u</tt> and <tt>-m</tt> options, the
549 merge result may need to overwrite paths that are not
550 tracked in the current branch. The command usually
551 refuses to proceed with the merge to avoid losing such a
552 path. However this safety valve sometimes gets in the
553 way. For example, it often happens that the other
554 branch added a file that used to be a generated file in
555 your branch, and the safety valve triggers when you try
556 to switch to that branch after you ran <tt>make</tt> but before
557 running <tt>make clean</tt> to remove the generated file. This
558 option tells the command to read per-directory exclude
559 file (usually <em>.gitignore</em>) and allows such an untracked
560 but explicitly ignored file to be overwritten.
561 </p>
562 </dd>
563 <dt class="hdlist1">
564 --index-output=&lt;file&gt;
565 </dt>
566 <dd>
568 Instead of writing the results out to <tt>$GIT_INDEX_FILE</tt>,
569 write the resulting index in the named file. While the
570 command is operating, the original index file is locked
571 with the same mechanism as usual. The file must allow
572 to be rename(2)ed into from a temporary file that is
573 created next to the usual index file; typically this
574 means it needs to be on the same filesystem as the index
575 file itself, and you need write permission to the
576 directories the index file and index output file are
577 located in.
578 </p>
579 </dd>
580 <dt class="hdlist1">
581 --no-sparse-checkout
582 </dt>
583 <dd>
585 Disable sparse checkout support even if <tt>core.sparseCheckout</tt>
586 is true.
587 </p>
588 </dd>
589 <dt class="hdlist1">
590 &lt;tree-ish#&gt;
591 </dt>
592 <dd>
594 The id of the tree object(s) to be read/merged.
595 </p>
596 </dd>
597 </dl></div>
598 </div>
599 <h2 id="_merging">Merging</h2>
600 <div class="sectionbody">
601 <div class="paragraph"><p>If <tt>-m</tt> is specified, <em>git read-tree</em> can perform 3 kinds of
602 merge, a single tree merge if only 1 tree is given, a
603 fast-forward merge with 2 trees, or a 3-way merge if 3 trees are
604 provided.</p></div>
605 <h3 id="_single_tree_merge">Single Tree Merge</h3><div style="clear:left"></div>
606 <div class="paragraph"><p>If only 1 tree is specified, <em>git read-tree</em> operates as if the user did not
607 specify <tt>-m</tt>, except that if the original index has an entry for a
608 given pathname, and the contents of the path match with the tree
609 being read, the stat info from the index is used. (In other words, the
610 index&#8217;s stat()s take precedence over the merged tree&#8217;s).</p></div>
611 <div class="paragraph"><p>That means that if you do a <tt>git read-tree -m &lt;newtree&gt;</tt> followed by a
612 <tt>git checkout-index -f -u -a</tt>, the <em>git checkout-index</em> only checks out
613 the stuff that really changed.</p></div>
614 <div class="paragraph"><p>This is used to avoid unnecessary false hits when <em>git diff-files</em> is
615 run after <em>git read-tree</em>.</p></div>
616 <h3 id="_two_tree_merge">Two Tree Merge</h3><div style="clear:left"></div>
617 <div class="paragraph"><p>Typically, this is invoked as <tt>git read-tree -m $H $M</tt>, where $H
618 is the head commit of the current repository, and $M is the head
619 of a foreign tree, which is simply ahead of $H (i.e. we are in a
620 fast-forward situation).</p></div>
621 <div class="paragraph"><p>When two trees are specified, the user is telling <em>git read-tree</em>
622 the following:</p></div>
623 <div class="olist arabic"><ol class="arabic">
624 <li>
626 The current index and work tree is derived from $H, but
627 the user may have local changes in them since $H.
628 </p>
629 </li>
630 <li>
632 The user wants to fast-forward to $M.
633 </p>
634 </li>
635 </ol></div>
636 <div class="paragraph"><p>In this case, the <tt>git read-tree -m $H $M</tt> command makes sure
637 that no local change is lost as the result of this "merge".
638 Here are the "carry forward" rules, where "I" denotes the index,
639 "clean" means that index and work tree coincide, and "exists"/"nothing"
640 refer to the presence of a path in the specified commit:</p></div>
641 <div class="tableblock">
642 <table rules="all"
643 width="100%"
644 frame="border"
645 cellspacing="0" cellpadding="4">
646 <col width="4%" />
647 <col width="20%" />
648 <col width="20%" />
649 <col width="20%" />
650 <col width="33%" />
651 <tbody>
652 <tr>
653 <td align="left" valign="top"><p class="table"></p></td>
654 <td align="left" valign="top"><p class="table">I</p></td>
655 <td align="left" valign="top"><p class="table">H</p></td>
656 <td align="left" valign="top"><p class="table">M</p></td>
657 <td align="left" valign="top"><p class="table">Result</p></td>
658 </tr>
659 <tr>
660 <td align="left" valign="top"><p class="table">0</p></td>
661 <td align="left" valign="top"><p class="table">nothing</p></td>
662 <td align="left" valign="top"><p class="table">nothing</p></td>
663 <td align="left" valign="top"><p class="table">nothing</p></td>
664 <td align="left" valign="top"><p class="table">(does not happen)</p></td>
665 </tr>
666 <tr>
667 <td align="left" valign="top"><p class="table">1</p></td>
668 <td align="left" valign="top"><p class="table">nothing</p></td>
669 <td align="left" valign="top"><p class="table">nothing</p></td>
670 <td align="left" valign="top"><p class="table">exists</p></td>
671 <td align="left" valign="top"><p class="table">use M</p></td>
672 </tr>
673 <tr>
674 <td align="left" valign="top"><p class="table">2</p></td>
675 <td align="left" valign="top"><p class="table">nothing</p></td>
676 <td align="left" valign="top"><p class="table">exists</p></td>
677 <td align="left" valign="top"><p class="table">nothing</p></td>
678 <td align="left" valign="top"><p class="table">remove path from index</p></td>
679 </tr>
680 <tr>
681 <td rowspan="2" align="left" valign="top"><p class="table">3</p></td>
682 <td rowspan="2" align="left" valign="top"><p class="table">nothing</p></td>
683 <td rowspan="2" align="left" valign="top"><p class="table">exists</p></td>
684 <td align="left" valign="top"><p class="table">exists, H ==M</p></td>
685 <td align="left" valign="top"><p class="table">use M if "initial checkout", keep index otherwise</p></td>
686 </tr>
687 <tr>
688 <td align="left" valign="top"><p class="table">exists, H != M</p></td>
689 <td align="left" valign="top"><p class="table">fail</p></td>
690 </tr>
691 </tbody>
692 </table>
693 </div>
694 <div class="literalblock">
695 <div class="content">
696 <pre><tt> clean I==H I==M
697 ------------------
698 4 yes N/A N/A nothing nothing keep index
699 5 no N/A N/A nothing nothing keep index</tt></pre>
700 </div></div>
701 <div class="literalblock">
702 <div class="content">
703 <pre><tt>6 yes N/A yes nothing exists keep index
704 7 no N/A yes nothing exists keep index
705 8 yes N/A no nothing exists fail
706 9 no N/A no nothing exists fail</tt></pre>
707 </div></div>
708 <div class="literalblock">
709 <div class="content">
710 <pre><tt>10 yes yes N/A exists nothing remove path from index
711 11 no yes N/A exists nothing fail
712 12 yes no N/A exists nothing fail
713 13 no no N/A exists nothing fail</tt></pre>
714 </div></div>
715 <div class="literalblock">
716 <div class="content">
717 <pre><tt> clean (H==M)
718 ------
719 14 yes exists exists keep index
720 15 no exists exists keep index</tt></pre>
721 </div></div>
722 <div class="literalblock">
723 <div class="content">
724 <pre><tt> clean I==H I==M (H!=M)
725 ------------------
726 16 yes no no exists exists fail
727 17 no no no exists exists fail
728 18 yes no yes exists exists keep index
729 19 no no yes exists exists keep index
730 20 yes yes no exists exists use M
731 21 no yes no exists exists fail</tt></pre>
732 </div></div>
733 <div class="paragraph"><p>In all "keep index" cases, the index entry stays as in the
734 original index file. If the entry is not up to date,
735 <em>git read-tree</em> keeps the copy in the work tree intact when
736 operating under the -u flag.</p></div>
737 <div class="paragraph"><p>When this form of <em>git read-tree</em> returns successfully, you can
738 see which of the "local changes" that you made were carried forward by running
739 <tt>git diff-index --cached $M</tt>. Note that this does not
740 necessarily match what <tt>git diff-index --cached $H</tt> would have
741 produced before such a two tree merge. This is because of cases
742 18 and 19 --- if you already had the changes in $M (e.g. maybe
743 you picked it up via e-mail in a patch form), <tt>git diff-index
744 --cached $H</tt> would have told you about the change before this
745 merge, but it would not show in <tt>git diff-index --cached $M</tt>
746 output after the two-tree merge.</p></div>
747 <div class="paragraph"><p>Case 3 is slightly tricky and needs explanation. The result from this
748 rule logically should be to remove the path if the user staged the removal
749 of the path and then switching to a new branch. That however will prevent
750 the initial checkout from happening, so the rule is modified to use M (new
751 tree) only when the content of the index is empty. Otherwise the removal
752 of the path is kept as long as $H and $M are the same.</p></div>
753 <h3 id="_3_way_merge">3-Way Merge</h3><div style="clear:left"></div>
754 <div class="paragraph"><p>Each "index" entry has two bits worth of "stage" state. stage 0 is the
755 normal one, and is the only one you&#8217;d see in any kind of normal use.</p></div>
756 <div class="paragraph"><p>However, when you do <em>git read-tree</em> with three trees, the "stage"
757 starts out at 1.</p></div>
758 <div class="paragraph"><p>This means that you can do</p></div>
759 <div class="listingblock">
760 <div class="content">
761 <pre><tt>$ git read-tree -m &lt;tree1&gt; &lt;tree2&gt; &lt;tree3&gt;</tt></pre>
762 </div></div>
763 <div class="paragraph"><p>and you will end up with an index with all of the &lt;tree1&gt; entries in
764 "stage1", all of the &lt;tree2&gt; entries in "stage2" and all of the
765 &lt;tree3&gt; entries in "stage3". When performing a merge of another
766 branch into the current branch, we use the common ancestor tree
767 as &lt;tree1&gt;, the current branch head as &lt;tree2&gt;, and the other
768 branch head as &lt;tree3&gt;.</p></div>
769 <div class="paragraph"><p>Furthermore, <em>git read-tree</em> has special-case logic that says: if you see
770 a file that matches in all respects in the following states, it
771 "collapses" back to "stage0":</p></div>
772 <div class="ulist"><ul>
773 <li>
775 stage 2 and 3 are the same; take one or the other (it makes no
776 difference - the same work has been done on our branch in
777 stage 2 and their branch in stage 3)
778 </p>
779 </li>
780 <li>
782 stage 1 and stage 2 are the same and stage 3 is different; take
783 stage 3 (our branch in stage 2 did not do anything since the
784 ancestor in stage 1 while their branch in stage 3 worked on
786 </p>
787 </li>
788 <li>
790 stage 1 and stage 3 are the same and stage 2 is different take
791 stage 2 (we did something while they did nothing)
792 </p>
793 </li>
794 </ul></div>
795 <div class="paragraph"><p>The <em>git write-tree</em> command refuses to write a nonsensical tree, and it
796 will complain about unmerged entries if it sees a single entry that is not
797 stage 0.</p></div>
798 <div class="paragraph"><p>OK, this all sounds like a collection of totally nonsensical rules,
799 but it&#8217;s actually exactly what you want in order to do a fast
800 merge. The different stages represent the "result tree" (stage 0, aka
801 "merged"), the original tree (stage 1, aka "orig"), and the two trees
802 you are trying to merge (stage 2 and 3 respectively).</p></div>
803 <div class="paragraph"><p>The order of stages 1, 2 and 3 (hence the order of three
804 &lt;tree-ish&gt; command line arguments) are significant when you
805 start a 3-way merge with an index file that is already
806 populated. Here is an outline of how the algorithm works:</p></div>
807 <div class="ulist"><ul>
808 <li>
810 if a file exists in identical format in all three trees, it will
811 automatically collapse to "merged" state by <em>git read-tree</em>.
812 </p>
813 </li>
814 <li>
816 a file that has <em>any</em> difference what-so-ever in the three trees
817 will stay as separate entries in the index. It&#8217;s up to "porcelain
818 policy" to determine how to remove the non-0 stages, and insert a
819 merged version.
820 </p>
821 </li>
822 <li>
824 the index file saves and restores with all this information, so you
825 can merge things incrementally, but as long as it has entries in
826 stages 1/2/3 (i.e., "unmerged entries") you can&#8217;t write the result. So
827 now the merge algorithm ends up being really simple:
828 </p>
829 <div class="ulist"><ul>
830 <li>
832 you walk the index in order, and ignore all entries of stage 0,
833 since they&#8217;ve already been done.
834 </p>
835 </li>
836 <li>
838 if you find a "stage1", but no matching "stage2" or "stage3", you
839 know it&#8217;s been removed from both trees (it only existed in the
840 original tree), and you remove that entry.
841 </p>
842 </li>
843 <li>
845 if you find a matching "stage2" and "stage3" tree, you remove one
846 of them, and turn the other into a "stage0" entry. Remove any
847 matching "stage1" entry if it exists too. .. all the normal
848 trivial rules ..
849 </p>
850 </li>
851 </ul></div>
852 </li>
853 </ul></div>
854 <div class="paragraph"><p>You would normally use <em>git merge-index</em> with supplied
855 <em>git merge-one-file</em> to do this last step. The script updates
856 the files in the working tree as it merges each path and at the
857 end of a successful merge.</p></div>
858 <div class="paragraph"><p>When you start a 3-way merge with an index file that is already
859 populated, it is assumed that it represents the state of the
860 files in your work tree, and you can even have files with
861 changes unrecorded in the index file. It is further assumed
862 that this state is "derived" from the stage 2 tree. The 3-way
863 merge refuses to run if it finds an entry in the original index
864 file that does not match stage 2.</p></div>
865 <div class="paragraph"><p>This is done to prevent you from losing your work-in-progress
866 changes, and mixing your random changes in an unrelated merge
867 commit. To illustrate, suppose you start from what has been
868 committed last to your repository:</p></div>
869 <div class="listingblock">
870 <div class="content">
871 <pre><tt>$ JC=`git rev-parse --verify "HEAD^0"`
872 $ git checkout-index -f -u -a $JC</tt></pre>
873 </div></div>
874 <div class="paragraph"><p>You do random edits, without running <em>git update-index</em>. And then
875 you notice that the tip of your "upstream" tree has advanced
876 since you pulled from him:</p></div>
877 <div class="listingblock">
878 <div class="content">
879 <pre><tt>$ git fetch git://.... linus
880 $ LT=`cat .git/FETCH_HEAD`</tt></pre>
881 </div></div>
882 <div class="paragraph"><p>Your work tree is still based on your HEAD ($JC), but you have
883 some edits since. Three-way merge makes sure that you have not
884 added or modified index entries since $JC, and if you haven&#8217;t,
885 then does the right thing. So with the following sequence:</p></div>
886 <div class="listingblock">
887 <div class="content">
888 <pre><tt>$ git read-tree -m -u `git merge-base $JC $LT` $JC $LT
889 $ git merge-index git-merge-one-file -a
890 $ echo "Merge with Linus" | \
891 git commit-tree `git write-tree` -p $JC -p $LT</tt></pre>
892 </div></div>
893 <div class="paragraph"><p>what you would commit is a pure merge between $JC and $LT without
894 your work-in-progress changes, and your work tree would be
895 updated to the result of the merge.</p></div>
896 <div class="paragraph"><p>However, if you have local changes in the working tree that
897 would be overwritten by this merge, <em>git read-tree</em> will refuse
898 to run to prevent your changes from being lost.</p></div>
899 <div class="paragraph"><p>In other words, there is no need to worry about what exists only
900 in the working tree. When you have local changes in a part of
901 the project that is not involved in the merge, your changes do
902 not interfere with the merge, and are kept intact. When they
903 <strong>do</strong> interfere, the merge does not even start (<em>git read-tree</em>
904 complains loudly and fails without modifying anything). In such
905 a case, you can simply continue doing what you were in the
906 middle of doing, and when your working tree is ready (i.e. you
907 have finished your work-in-progress), attempt the merge again.</p></div>
908 </div>
909 <h2 id="_sparse_checkout">Sparse checkout</h2>
910 <div class="sectionbody">
911 <div class="paragraph"><p>"Sparse checkout" allows to sparsely populate working directory.
912 It uses skip-worktree bit (see <a href="git-update-index.html">git-update-index(1)</a>) to tell
913 Git whether a file on working directory is worth looking at.</p></div>
914 <div class="paragraph"><p>"git read-tree" and other merge-based commands ("git merge", "git
915 checkout"&#8230;) can help maintaining skip-worktree bitmap and working
916 directory update. <tt>$GIT_DIR/info/sparse-checkout</tt> is used to
917 define the skip-worktree reference bitmap. When "git read-tree" needs
918 to update working directory, it will reset skip-worktree bit in index
919 based on this file, which uses the same syntax as .gitignore files.
920 If an entry matches a pattern in this file, skip-worktree will be
921 set on that entry. Otherwise, skip-worktree will be unset.</p></div>
922 <div class="paragraph"><p>Then it compares the new skip-worktree value with the previous one. If
923 skip-worktree turns from unset to set, it will add the corresponding
924 file back. If it turns from set to unset, that file will be removed.</p></div>
925 <div class="paragraph"><p>While <tt>$GIT_DIR/info/sparse-checkout</tt> is usually used to specify what
926 files are in. You can also specify what files are <em>not</em> in, using
927 negate patterns. For example, to remove file "unwanted":</p></div>
928 <div class="listingblock">
929 <div class="content">
930 <pre><tt>*
931 !unwanted</tt></pre>
932 </div></div>
933 <div class="paragraph"><p>Another tricky thing is fully repopulating working directory when you
934 no longer want sparse checkout. You cannot just disable "sparse
935 checkout" because skip-worktree are still in the index and you working
936 directory is still sparsely populated. You should re-populate working
937 directory with the <tt>$GIT_DIR/info/sparse-checkout</tt> file content as
938 follows:</p></div>
939 <div class="listingblock">
940 <div class="content">
941 <pre><tt>*</tt></pre>
942 </div></div>
943 <div class="paragraph"><p>Then you can disable sparse checkout. Sparse checkout support in "git
944 read-tree" and similar commands is disabled by default. You need to
945 turn <tt>core.sparseCheckout</tt> on in order to have sparse checkout
946 support.</p></div>
947 </div>
948 <h2 id="_see_also">SEE ALSO</h2>
949 <div class="sectionbody">
950 <div class="paragraph"><p><a href="git-write-tree.html">git-write-tree(1)</a>; <a href="git-ls-files.html">git-ls-files(1)</a>;
951 <a href="gitignore.html">gitignore(5)</a></p></div>
952 </div>
953 <h2 id="_author">Author</h2>
954 <div class="sectionbody">
955 <div class="paragraph"><p>Written by Linus Torvalds &lt;<a href="mailto:torvalds@osdl.org">torvalds@osdl.org</a>&gt;</p></div>
956 </div>
957 <h2 id="_documentation">Documentation</h2>
958 <div class="sectionbody">
959 <div class="paragraph"><p>Documentation by David Greaves, Junio C Hamano and the git-list &lt;<a href="mailto:git@vger.kernel.org">git@vger.kernel.org</a>&gt;.</p></div>
960 </div>
961 <h2 id="_git">GIT</h2>
962 <div class="sectionbody">
963 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
964 </div>
965 <div id="footer">
966 <div id="footer-text">
967 Last updated 2010-04-30 16:44:58 CEST
968 </div>
969 </div>
970 </body>
971 </html>