Autogenerated HTML docs for v1.7.7-237-g34c44
[git/jnareb-git.git] / git-read-tree.html
blob3f96eb50d10aa3368d5580cb579810310a196922
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.5.2" />
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.0em;
122 margin-bottom: 1.5em;
124 div.admonitionblock {
125 margin-top: 2.0em;
126 margin-bottom: 2.0em;
127 margin-right: 10%;
128 color: #606060;
131 div.content { /* Block element content. */
132 padding: 0;
135 /* Block element titles. */
136 div.title, caption.title {
137 color: #527bbd;
138 font-family: sans-serif;
139 font-weight: bold;
140 text-align: left;
141 margin-top: 1.0em;
142 margin-bottom: 0.5em;
144 div.title + * {
145 margin-top: 0;
148 td div.title:first-child {
149 margin-top: 0.0em;
151 div.content div.title:first-child {
152 margin-top: 0.0em;
154 div.content + div.title {
155 margin-top: 0.0em;
158 div.sidebarblock > div.content {
159 background: #ffffee;
160 border: 1px solid silver;
161 padding: 0.5em;
164 div.listingblock > div.content {
165 border: 1px solid silver;
166 background: #f4f4f4;
167 padding: 0.5em;
170 div.quoteblock, div.verseblock {
171 padding-left: 1.0em;
172 margin-left: 1.0em;
173 margin-right: 10%;
174 border-left: 5px solid #dddddd;
175 color: #777777;
178 div.quoteblock > div.attribution {
179 padding-top: 0.5em;
180 text-align: right;
183 div.verseblock > div.content {
184 white-space: pre;
186 div.verseblock > div.attribution {
187 padding-top: 0.75em;
188 text-align: left;
190 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
191 div.verseblock + div.attribution {
192 text-align: left;
195 div.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;
203 div.admonitionblock td.content {
204 padding-left: 0.5em;
205 border-left: 3px solid #dddddd;
208 div.exampleblock > div.content {
209 border-left: 3px solid #dddddd;
210 padding-left: 0.5em;
213 div.imageblock div.content { padding-left: 0; }
214 span.image img { border-style: none; }
215 a.image:visited { color: white; }
217 dl {
218 margin-top: 0.8em;
219 margin-bottom: 0.8em;
221 dt {
222 margin-top: 0.5em;
223 margin-bottom: 0;
224 font-style: normal;
225 color: navy;
227 dd > *:first-child {
228 margin-top: 0.1em;
231 ul, ol {
232 list-style-position: outside;
234 ol.arabic {
235 list-style-type: decimal;
237 ol.loweralpha {
238 list-style-type: lower-alpha;
240 ol.upperalpha {
241 list-style-type: upper-alpha;
243 ol.lowerroman {
244 list-style-type: lower-roman;
246 ol.upperroman {
247 list-style-type: upper-roman;
250 div.compact ul, div.compact ol,
251 div.compact p, div.compact p,
252 div.compact div, div.compact div {
253 margin-top: 0.1em;
254 margin-bottom: 0.1em;
257 div.tableblock > table {
258 border: 3px solid #527bbd;
260 thead, p.table.header {
261 font-family: sans-serif;
262 font-weight: bold;
264 tfoot {
265 font-weight: bold;
267 td > div.verse {
268 white-space: pre;
270 p.table {
271 margin-top: 0;
273 /* Because the table frame attribute is overriden by CSS in most browsers. */
274 div.tableblock > table[frame="void"] {
275 border-style: none;
277 div.tableblock > table[frame="hsides"] {
278 border-left-style: none;
279 border-right-style: none;
281 div.tableblock > table[frame="vsides"] {
282 border-top-style: none;
283 border-bottom-style: none;
287 div.hdlist {
288 margin-top: 0.8em;
289 margin-bottom: 0.8em;
291 div.hdlist tr {
292 padding-bottom: 15px;
294 dt.hdlist1.strong, td.hdlist1.strong {
295 font-weight: bold;
297 td.hdlist1 {
298 vertical-align: top;
299 font-style: normal;
300 padding-right: 0.8em;
301 color: navy;
303 td.hdlist2 {
304 vertical-align: top;
306 div.hdlist.compact tr {
307 margin: 0;
308 padding-bottom: 0;
311 .comment {
312 background: yellow;
315 .footnote, .footnoteref {
316 font-size: 0.8em;
319 span.footnote, span.footnoteref {
320 vertical-align: super;
323 #footnotes {
324 margin: 20px 0 20px 0;
325 padding: 7px 0 0 0;
328 #footnotes div.footnote {
329 margin: 0 0 5px 0;
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;
343 @media print {
344 div#footer-badges { display: none; }
347 div#toc {
348 margin-bottom: 2.5em;
351 div#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;
360 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
361 margin-top: 0;
362 margin-bottom: 0;
364 div.toclevel2 {
365 margin-left: 2em;
366 font-size: 0.9em;
368 div.toclevel3 {
369 margin-left: 4em;
370 font-size: 0.9em;
372 div.toclevel4 {
373 margin-left: 6em;
374 font-size: 0.9em;
376 /* Overrides for manpage documents */
377 h1 {
378 padding-top: 0.5em;
379 padding-bottom: 0.5em;
380 border-top: 2px solid silver;
381 border-bottom: 2px solid silver;
383 h2 {
384 border-style: none;
386 div.sectionbody {
387 margin-left: 5%;
390 @media print {
391 div#toc { display: none; }
394 /* Workarounds for IE6's broken and incomplete CSS2. */
396 div.sidebar-content {
397 background: #ffffee;
398 border: 1px solid silver;
399 padding: 0.5em;
401 div.sidebar-title, div.image-title {
402 color: #527bbd;
403 font-family: sans-serif;
404 font-weight: bold;
405 margin-top: 0.0em;
406 margin-bottom: 0.5em;
409 div.listingblock div.content {
410 border: 1px solid silver;
411 background: #f4f4f4;
412 padding: 0.5em;
415 div.quoteblock-attribution {
416 padding-top: 0.5em;
417 text-align: right;
420 div.verseblock-content {
421 white-space: pre;
423 div.verseblock-attribution {
424 padding-top: 0.75em;
425 text-align: left;
428 div.exampleblock-content {
429 border-left: 3px solid #dddddd;
430 padding-left: 0.5em;
433 /* IE6 sets dynamically generated links as visited. */
434 div#toc a:visited { color: blue; }
435 </style>
436 <script type="text/javascript">
437 /*<![CDATA[*/
438 window.onload = function(){asciidoc.footnotes();}
439 var asciidoc = { // Namespace.
441 /////////////////////////////////////////////////////////////////////
442 // Table Of Contents generator
443 /////////////////////////////////////////////////////////////////////
445 /* Author: Mihai Bazon, September 2002
446 * http://students.infoiasi.ro/~mishoo
448 * Table Of Content generator
449 * Version: 0.4
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.
455 /* modified by Troy D. Hanson, September 2006. License: GPL */
456 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
458 // toclevels = 1..4.
459 toc: function (toclevels) {
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);
469 return text;
472 function TocEntry(el, text, toclevel) {
473 this.element = el;
474 this.text = text;
475 this.toclevel = toclevel;
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);
491 iterate(i);
495 iterate(el);
496 return result;
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);
513 if (entries.length == 0)
514 toc.parentNode.removeChild(toc);
518 /////////////////////////////////////////////////////////////////////
519 // Footnotes generator
520 /////////////////////////////////////////////////////////////////////
522 /* Based on footnote generation code from:
523 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
526 footnotes: 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;
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>]";
567 /*]]>*/
568 </script>
569 </head>
570 <body>
571 <div id="header">
572 <h1>
573 git-read-tree(1) Manual Page
574 </h1>
575 <h2>NAME</h2>
576 <div class="sectionbody">
577 <p>git-read-tree -
578 Reads tree information into the index
579 </p>
580 </div>
581 </div>
582 <div id="content">
583 <h2 id="_synopsis">SYNOPSIS</h2>
584 <div class="sectionbody">
585 <div class="verseblock">
586 <div class="verseblock-content"><em>git read-tree</em> [[-m [--trivial] [--aggressive] | --reset | --prefix=&lt;prefix&gt;]
587 [-u [--exclude-per-directory=&lt;gitignore&gt;] | -i]]
588 [--index-output=&lt;file&gt;] [--no-sparse-checkout]
589 (--empty | &lt;tree-ish1&gt; [&lt;tree-ish2&gt; [&lt;tree-ish3&gt;]])</div>
590 <div class="verseblock-attribution">
591 </div></div>
592 </div>
593 <h2 id="_description">DESCRIPTION</h2>
594 <div class="sectionbody">
595 <div class="paragraph"><p>Reads the tree information given by &lt;tree-ish&gt; into the index,
596 but does not actually <strong>update</strong> any of the files it "caches". (see:
597 <a href="git-checkout-index.html">git-checkout-index(1)</a>)</p></div>
598 <div class="paragraph"><p>Optionally, it can merge a tree into the index, perform a
599 fast-forward (i.e. 2-way) merge, or a 3-way merge, with the <tt>-m</tt>
600 flag. When used with <tt>-m</tt>, the <tt>-u</tt> flag causes it to also update
601 the files in the work tree with the result of the merge.</p></div>
602 <div class="paragraph"><p>Trivial merges are done by <em>git read-tree</em> itself. Only conflicting paths
603 will be in unmerged state when <em>git read-tree</em> returns.</p></div>
604 </div>
605 <h2 id="_options">OPTIONS</h2>
606 <div class="sectionbody">
607 <div class="dlist"><dl>
608 <dt class="hdlist1">
610 </dt>
611 <dd>
613 Perform a merge, not just a read. The command will
614 refuse to run if your index file has unmerged entries,
615 indicating that you have not finished previous merge you
616 started.
617 </p>
618 </dd>
619 <dt class="hdlist1">
620 --reset
621 </dt>
622 <dd>
624 Same as -m, except that unmerged entries are discarded
625 instead of failing.
626 </p>
627 </dd>
628 <dt class="hdlist1">
630 </dt>
631 <dd>
633 After a successful merge, update the files in the work
634 tree with the result of the merge.
635 </p>
636 </dd>
637 <dt class="hdlist1">
639 </dt>
640 <dd>
642 Usually a merge requires the index file as well as the
643 files in the working tree to be up to date with the
644 current head commit, in order not to lose local
645 changes. This flag disables the check with the working
646 tree and is meant to be used when creating a merge of
647 trees that are not directly related to the current
648 working tree status into a temporary index file.
649 </p>
650 </dd>
651 <dt class="hdlist1">
653 </dt>
654 <dt class="hdlist1">
655 --dry-run
656 </dt>
657 <dd>
659 Check if the command would error out, without updating the index
660 nor the files in the working tree for real.
661 </p>
662 </dd>
663 <dt class="hdlist1">
665 </dt>
666 <dd>
668 Show the progress of checking files out.
669 </p>
670 </dd>
671 <dt class="hdlist1">
672 --trivial
673 </dt>
674 <dd>
676 Restrict three-way merge by <em>git read-tree</em> to happen
677 only if there is no file-level merging required, instead
678 of resolving merge for trivial cases and leaving
679 conflicting files unresolved in the index.
680 </p>
681 </dd>
682 <dt class="hdlist1">
683 --aggressive
684 </dt>
685 <dd>
687 Usually a three-way merge by <em>git read-tree</em> resolves
688 the merge for really trivial cases and leaves other
689 cases unresolved in the index, so that porcelains can
690 implement different merge policies. This flag makes the
691 command resolve a few more cases internally:
692 </p>
693 <div class="ulist"><ul>
694 <li>
696 when one side removes a path and the other side leaves the path
697 unmodified. The resolution is to remove that path.
698 </p>
699 </li>
700 <li>
702 when both sides remove a path. The resolution is to remove that path.
703 </p>
704 </li>
705 <li>
707 when both sides add a path identically. The resolution
708 is to add that path.
709 </p>
710 </li>
711 </ul></div>
712 </dd>
713 <dt class="hdlist1">
714 --prefix=&lt;prefix&gt;/
715 </dt>
716 <dd>
718 Keep the current index contents, and read the contents
719 of the named tree-ish under the directory at <tt>&lt;prefix&gt;</tt>. The
720 original index file cannot have anything at the path
721 <tt>&lt;prefix&gt;</tt> itself, nor anything in the <tt>&lt;prefix&gt;/</tt>
722 directory. Note that the <tt>&lt;prefix&gt;/</tt> value must end
723 with a slash.
724 </p>
725 </dd>
726 <dt class="hdlist1">
727 --exclude-per-directory=&lt;gitignore&gt;
728 </dt>
729 <dd>
731 When running the command with <tt>-u</tt> and <tt>-m</tt> options, the
732 merge result may need to overwrite paths that are not
733 tracked in the current branch. The command usually
734 refuses to proceed with the merge to avoid losing such a
735 path. However this safety valve sometimes gets in the
736 way. For example, it often happens that the other
737 branch added a file that used to be a generated file in
738 your branch, and the safety valve triggers when you try
739 to switch to that branch after you ran <tt>make</tt> but before
740 running <tt>make clean</tt> to remove the generated file. This
741 option tells the command to read per-directory exclude
742 file (usually <em>.gitignore</em>) and allows such an untracked
743 but explicitly ignored file to be overwritten.
744 </p>
745 </dd>
746 <dt class="hdlist1">
747 --index-output=&lt;file&gt;
748 </dt>
749 <dd>
751 Instead of writing the results out to <tt>$GIT_INDEX_FILE</tt>,
752 write the resulting index in the named file. While the
753 command is operating, the original index file is locked
754 with the same mechanism as usual. The file must allow
755 to be rename(2)ed into from a temporary file that is
756 created next to the usual index file; typically this
757 means it needs to be on the same filesystem as the index
758 file itself, and you need write permission to the
759 directories the index file and index output file are
760 located in.
761 </p>
762 </dd>
763 <dt class="hdlist1">
764 --no-sparse-checkout
765 </dt>
766 <dd>
768 Disable sparse checkout support even if <tt>core.sparseCheckout</tt>
769 is true.
770 </p>
771 </dd>
772 <dt class="hdlist1">
773 --empty
774 </dt>
775 <dd>
777 Instead of reading tree object(s) into the index, just empty
779 </p>
780 </dd>
781 <dt class="hdlist1">
782 &lt;tree-ish#&gt;
783 </dt>
784 <dd>
786 The id of the tree object(s) to be read/merged.
787 </p>
788 </dd>
789 </dl></div>
790 </div>
791 <h2 id="_merging">Merging</h2>
792 <div class="sectionbody">
793 <div class="paragraph"><p>If <tt>-m</tt> is specified, <em>git read-tree</em> can perform 3 kinds of
794 merge, a single tree merge if only 1 tree is given, a
795 fast-forward merge with 2 trees, or a 3-way merge if 3 trees are
796 provided.</p></div>
797 <h3 id="_single_tree_merge">Single Tree Merge</h3><div style="clear:left"></div>
798 <div class="paragraph"><p>If only 1 tree is specified, <em>git read-tree</em> operates as if the user did not
799 specify <tt>-m</tt>, except that if the original index has an entry for a
800 given pathname, and the contents of the path match with the tree
801 being read, the stat info from the index is used. (In other words, the
802 index&#8217;s stat()s take precedence over the merged tree&#8217;s).</p></div>
803 <div class="paragraph"><p>That means that if you do a <tt>git read-tree -m &lt;newtree&gt;</tt> followed by a
804 <tt>git checkout-index -f -u -a</tt>, the <em>git checkout-index</em> only checks out
805 the stuff that really changed.</p></div>
806 <div class="paragraph"><p>This is used to avoid unnecessary false hits when <em>git diff-files</em> is
807 run after <em>git read-tree</em>.</p></div>
808 <h3 id="_two_tree_merge">Two Tree Merge</h3><div style="clear:left"></div>
809 <div class="paragraph"><p>Typically, this is invoked as <tt>git read-tree -m $H $M</tt>, where $H
810 is the head commit of the current repository, and $M is the head
811 of a foreign tree, which is simply ahead of $H (i.e. we are in a
812 fast-forward situation).</p></div>
813 <div class="paragraph"><p>When two trees are specified, the user is telling <em>git read-tree</em>
814 the following:</p></div>
815 <div class="olist arabic"><ol class="arabic">
816 <li>
818 The current index and work tree is derived from $H, but
819 the user may have local changes in them since $H.
820 </p>
821 </li>
822 <li>
824 The user wants to fast-forward to $M.
825 </p>
826 </li>
827 </ol></div>
828 <div class="paragraph"><p>In this case, the <tt>git read-tree -m $H $M</tt> command makes sure
829 that no local change is lost as the result of this "merge".
830 Here are the "carry forward" rules, where "I" denotes the index,
831 "clean" means that index and work tree coincide, and "exists"/"nothing"
832 refer to the presence of a path in the specified commit:</p></div>
833 <div class="literalblock">
834 <div class="content">
835 <pre><tt> I H M Result
836 -------------------------------------------------------
837 0 nothing nothing nothing (does not happen)
838 1 nothing nothing exists use M
839 2 nothing exists nothing remove path from index
840 3 nothing exists exists, use M if "initial checkout",
841 H == M keep index otherwise
842 exists, fail
843 H != M</tt></pre>
844 </div></div>
845 <div class="literalblock">
846 <div class="content">
847 <pre><tt> clean I==H I==M
848 ------------------
849 4 yes N/A N/A nothing nothing keep index
850 5 no N/A N/A nothing nothing keep index</tt></pre>
851 </div></div>
852 <div class="literalblock">
853 <div class="content">
854 <pre><tt>6 yes N/A yes nothing exists keep index
855 7 no N/A yes nothing exists keep index
856 8 yes N/A no nothing exists fail
857 9 no N/A no nothing exists fail</tt></pre>
858 </div></div>
859 <div class="literalblock">
860 <div class="content">
861 <pre><tt>10 yes yes N/A exists nothing remove path from index
862 11 no yes N/A exists nothing fail
863 12 yes no N/A exists nothing fail
864 13 no no N/A exists nothing fail</tt></pre>
865 </div></div>
866 <div class="literalblock">
867 <div class="content">
868 <pre><tt> clean (H==M)
869 ------
870 14 yes exists exists keep index
871 15 no exists exists keep index</tt></pre>
872 </div></div>
873 <div class="literalblock">
874 <div class="content">
875 <pre><tt> clean I==H I==M (H!=M)
876 ------------------
877 16 yes no no exists exists fail
878 17 no no no exists exists fail
879 18 yes no yes exists exists keep index
880 19 no no yes exists exists keep index
881 20 yes yes no exists exists use M
882 21 no yes no exists exists fail</tt></pre>
883 </div></div>
884 <div class="paragraph"><p>In all "keep index" cases, the index entry stays as in the
885 original index file. If the entry is not up to date,
886 <em>git read-tree</em> keeps the copy in the work tree intact when
887 operating under the -u flag.</p></div>
888 <div class="paragraph"><p>When this form of <em>git read-tree</em> returns successfully, you can
889 see which of the "local changes" that you made were carried forward by running
890 <tt>git diff-index --cached $M</tt>. Note that this does not
891 necessarily match what <tt>git diff-index --cached $H</tt> would have
892 produced before such a two tree merge. This is because of cases
893 18 and 19 --- if you already had the changes in $M (e.g. maybe
894 you picked it up via e-mail in a patch form), <tt>git diff-index
895 --cached $H</tt> would have told you about the change before this
896 merge, but it would not show in <tt>git diff-index --cached $M</tt>
897 output after the two-tree merge.</p></div>
898 <div class="paragraph"><p>Case 3 is slightly tricky and needs explanation. The result from this
899 rule logically should be to remove the path if the user staged the removal
900 of the path and then switching to a new branch. That however will prevent
901 the initial checkout from happening, so the rule is modified to use M (new
902 tree) only when the content of the index is empty. Otherwise the removal
903 of the path is kept as long as $H and $M are the same.</p></div>
904 <h3 id="_3_way_merge">3-Way Merge</h3><div style="clear:left"></div>
905 <div class="paragraph"><p>Each "index" entry has two bits worth of "stage" state. stage 0 is the
906 normal one, and is the only one you&#8217;d see in any kind of normal use.</p></div>
907 <div class="paragraph"><p>However, when you do <em>git read-tree</em> with three trees, the "stage"
908 starts out at 1.</p></div>
909 <div class="paragraph"><p>This means that you can do</p></div>
910 <div class="listingblock">
911 <div class="content">
912 <pre><tt>$ git read-tree -m &lt;tree1&gt; &lt;tree2&gt; &lt;tree3&gt;</tt></pre>
913 </div></div>
914 <div class="paragraph"><p>and you will end up with an index with all of the &lt;tree1&gt; entries in
915 "stage1", all of the &lt;tree2&gt; entries in "stage2" and all of the
916 &lt;tree3&gt; entries in "stage3". When performing a merge of another
917 branch into the current branch, we use the common ancestor tree
918 as &lt;tree1&gt;, the current branch head as &lt;tree2&gt;, and the other
919 branch head as &lt;tree3&gt;.</p></div>
920 <div class="paragraph"><p>Furthermore, <em>git read-tree</em> has special-case logic that says: if you see
921 a file that matches in all respects in the following states, it
922 "collapses" back to "stage0":</p></div>
923 <div class="ulist"><ul>
924 <li>
926 stage 2 and 3 are the same; take one or the other (it makes no
927 difference - the same work has been done on our branch in
928 stage 2 and their branch in stage 3)
929 </p>
930 </li>
931 <li>
933 stage 1 and stage 2 are the same and stage 3 is different; take
934 stage 3 (our branch in stage 2 did not do anything since the
935 ancestor in stage 1 while their branch in stage 3 worked on
937 </p>
938 </li>
939 <li>
941 stage 1 and stage 3 are the same and stage 2 is different take
942 stage 2 (we did something while they did nothing)
943 </p>
944 </li>
945 </ul></div>
946 <div class="paragraph"><p>The <em>git write-tree</em> command refuses to write a nonsensical tree, and it
947 will complain about unmerged entries if it sees a single entry that is not
948 stage 0.</p></div>
949 <div class="paragraph"><p>OK, this all sounds like a collection of totally nonsensical rules,
950 but it&#8217;s actually exactly what you want in order to do a fast
951 merge. The different stages represent the "result tree" (stage 0, aka
952 "merged"), the original tree (stage 1, aka "orig"), and the two trees
953 you are trying to merge (stage 2 and 3 respectively).</p></div>
954 <div class="paragraph"><p>The order of stages 1, 2 and 3 (hence the order of three
955 &lt;tree-ish&gt; command line arguments) are significant when you
956 start a 3-way merge with an index file that is already
957 populated. Here is an outline of how the algorithm works:</p></div>
958 <div class="ulist"><ul>
959 <li>
961 if a file exists in identical format in all three trees, it will
962 automatically collapse to "merged" state by <em>git read-tree</em>.
963 </p>
964 </li>
965 <li>
967 a file that has <em>any</em> difference what-so-ever in the three trees
968 will stay as separate entries in the index. It&#8217;s up to "porcelain
969 policy" to determine how to remove the non-0 stages, and insert a
970 merged version.
971 </p>
972 </li>
973 <li>
975 the index file saves and restores with all this information, so you
976 can merge things incrementally, but as long as it has entries in
977 stages 1/2/3 (i.e., "unmerged entries") you can&#8217;t write the result. So
978 now the merge algorithm ends up being really simple:
979 </p>
980 <div class="ulist"><ul>
981 <li>
983 you walk the index in order, and ignore all entries of stage 0,
984 since they&#8217;ve already been done.
985 </p>
986 </li>
987 <li>
989 if you find a "stage1", but no matching "stage2" or "stage3", you
990 know it&#8217;s been removed from both trees (it only existed in the
991 original tree), and you remove that entry.
992 </p>
993 </li>
994 <li>
996 if you find a matching "stage2" and "stage3" tree, you remove one
997 of them, and turn the other into a "stage0" entry. Remove any
998 matching "stage1" entry if it exists too. .. all the normal
999 trivial rules ..
1000 </p>
1001 </li>
1002 </ul></div>
1003 </li>
1004 </ul></div>
1005 <div class="paragraph"><p>You would normally use <em>git merge-index</em> with supplied
1006 <em>git merge-one-file</em> to do this last step. The script updates
1007 the files in the working tree as it merges each path and at the
1008 end of a successful merge.</p></div>
1009 <div class="paragraph"><p>When you start a 3-way merge with an index file that is already
1010 populated, it is assumed that it represents the state of the
1011 files in your work tree, and you can even have files with
1012 changes unrecorded in the index file. It is further assumed
1013 that this state is "derived" from the stage 2 tree. The 3-way
1014 merge refuses to run if it finds an entry in the original index
1015 file that does not match stage 2.</p></div>
1016 <div class="paragraph"><p>This is done to prevent you from losing your work-in-progress
1017 changes, and mixing your random changes in an unrelated merge
1018 commit. To illustrate, suppose you start from what has been
1019 committed last to your repository:</p></div>
1020 <div class="listingblock">
1021 <div class="content">
1022 <pre><tt>$ JC=`git rev-parse --verify "HEAD^0"`
1023 $ git checkout-index -f -u -a $JC</tt></pre>
1024 </div></div>
1025 <div class="paragraph"><p>You do random edits, without running <em>git update-index</em>. And then
1026 you notice that the tip of your "upstream" tree has advanced
1027 since you pulled from him:</p></div>
1028 <div class="listingblock">
1029 <div class="content">
1030 <pre><tt>$ git fetch git://.... linus
1031 $ LT=`cat .git/FETCH_HEAD`</tt></pre>
1032 </div></div>
1033 <div class="paragraph"><p>Your work tree is still based on your HEAD ($JC), but you have
1034 some edits since. Three-way merge makes sure that you have not
1035 added or modified index entries since $JC, and if you haven&#8217;t,
1036 then does the right thing. So with the following sequence:</p></div>
1037 <div class="listingblock">
1038 <div class="content">
1039 <pre><tt>$ git read-tree -m -u `git merge-base $JC $LT` $JC $LT
1040 $ git merge-index git-merge-one-file -a
1041 $ echo "Merge with Linus" | \
1042 git commit-tree `git write-tree` -p $JC -p $LT</tt></pre>
1043 </div></div>
1044 <div class="paragraph"><p>what you would commit is a pure merge between $JC and $LT without
1045 your work-in-progress changes, and your work tree would be
1046 updated to the result of the merge.</p></div>
1047 <div class="paragraph"><p>However, if you have local changes in the working tree that
1048 would be overwritten by this merge, <em>git read-tree</em> will refuse
1049 to run to prevent your changes from being lost.</p></div>
1050 <div class="paragraph"><p>In other words, there is no need to worry about what exists only
1051 in the working tree. When you have local changes in a part of
1052 the project that is not involved in the merge, your changes do
1053 not interfere with the merge, and are kept intact. When they
1054 <strong>do</strong> interfere, the merge does not even start (<em>git read-tree</em>
1055 complains loudly and fails without modifying anything). In such
1056 a case, you can simply continue doing what you were in the
1057 middle of doing, and when your working tree is ready (i.e. you
1058 have finished your work-in-progress), attempt the merge again.</p></div>
1059 </div>
1060 <h2 id="_sparse_checkout">Sparse checkout</h2>
1061 <div class="sectionbody">
1062 <div class="paragraph"><p>"Sparse checkout" allows populating the working directory sparsely.
1063 It uses the skip-worktree bit (see <a href="git-update-index.html">git-update-index(1)</a>) to tell
1064 Git whether a file in the working directory is worth looking at.</p></div>
1065 <div class="paragraph"><p><em>git read-tree</em> and other merge-based commands (<em>git merge</em>, <em>git
1066 checkout</em>&#8230;) can help maintaining the skip-worktree bitmap and working
1067 directory update. <tt>$GIT_DIR/info/sparse-checkout</tt> is used to
1068 define the skip-worktree reference bitmap. When <em>git read-tree</em> needs
1069 to update the working directory, it resets the skip-worktree bit in the index
1070 based on this file, which uses the same syntax as .gitignore files.
1071 If an entry matches a pattern in this file, skip-worktree will not be
1072 set on that entry. Otherwise, skip-worktree will be set.</p></div>
1073 <div class="paragraph"><p>Then it compares the new skip-worktree value with the previous one. If
1074 skip-worktree turns from set to unset, it will add the corresponding
1075 file back. If it turns from unset to set, that file will be removed.</p></div>
1076 <div class="paragraph"><p>While <tt>$GIT_DIR/info/sparse-checkout</tt> is usually used to specify what
1077 files are in, you can also specify what files are <em>not</em> in, using
1078 negate patterns. For example, to remove the file <tt>unwanted</tt>:</p></div>
1079 <div class="listingblock">
1080 <div class="content">
1081 <pre><tt>/*
1082 !unwanted</tt></pre>
1083 </div></div>
1084 <div class="paragraph"><p>Another tricky thing is fully repopulating the working directory when you
1085 no longer want sparse checkout. You cannot just disable "sparse
1086 checkout" because skip-worktree bits are still in the index and your working
1087 directory is still sparsely populated. You should re-populate the working
1088 directory with the <tt>$GIT_DIR/info/sparse-checkout</tt> file content as
1089 follows:</p></div>
1090 <div class="listingblock">
1091 <div class="content">
1092 <pre><tt>/*</tt></pre>
1093 </div></div>
1094 <div class="paragraph"><p>Then you can disable sparse checkout. Sparse checkout support in <em>git
1095 read-tree</em> and similar commands is disabled by default. You need to
1096 turn <tt>core.sparseCheckout</tt> on in order to have sparse checkout
1097 support.</p></div>
1098 </div>
1099 <h2 id="_see_also">SEE ALSO</h2>
1100 <div class="sectionbody">
1101 <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>;
1102 <a href="gitignore.html">gitignore(5)</a></p></div>
1103 </div>
1104 <h2 id="_git">GIT</h2>
1105 <div class="sectionbody">
1106 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1107 </div>
1108 </div>
1109 <div id="footnotes"><hr /></div>
1110 <div id="footer">
1111 <div id="footer-text">
1112 Last updated 2011-10-10 16:42:04 PDT
1113 </div>
1114 </div>
1115 </body>
1116 </html>