Autogenerated HTML docs for v1.2.0-g6a9b
[git.git] / git-read-tree.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\r
2     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\r
4 <head>\r
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
6 <meta name="generator" content="AsciiDoc 7.0.1" />\r
7 <style type="text/css">\r
8 /* Debug borders */\r
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {\r
10 /*\r
11   border: 1px solid red;\r
12 */\r
13 }\r
14 \r
15 body {\r
16   margin: 1em 5% 1em 5%;\r
17 }\r
18 \r
19 a { color: blue; }\r
20 a:visited { color: fuchsia; }\r
21 \r
22 em {\r
23   font-style: italic;\r
24 }\r
25 \r
26 strong {\r
27   font-weight: bold;\r
28 }\r
29 \r
30 tt {\r
31   color: navy;\r
32 }\r
33 \r
34 h1, h2, h3, h4, h5, h6 {\r
35   color: #527bbd;\r
36   font-family: sans-serif;\r
37   margin-top: 1.2em;\r
38   margin-bottom: 0.5em;\r
39   line-height: 1.3;\r
40 }\r
41 \r
42 h1 {\r
43   border-bottom: 2px solid silver;\r
44 }\r
45 h2 {\r
46   border-bottom: 2px solid silver;\r
47   padding-top: 0.5em;\r
48 }\r
49 \r
50 div.sectionbody {\r
51   font-family: serif;\r
52   margin-left: 0;\r
53 }\r
54 \r
55 hr {\r
56   border: 1px solid silver;\r
57 }\r
58 \r
59 p {\r
60   margin-top: 0.5em;\r
61   margin-bottom: 0.5em;\r
62 }\r
63 \r
64 pre {\r
65   padding: 0;\r
66   margin: 0;\r
67 }\r
68 \r
69 span#author {\r
70   color: #527bbd;\r
71   font-family: sans-serif;\r
72   font-weight: bold;\r
73   font-size: 1.2em;\r
74 }\r
75 span#email {\r
76 }\r
77 span#revision {\r
78   font-family: sans-serif;\r
79 }\r
80 \r
81 div#footer {\r
82   font-family: sans-serif;\r
83   font-size: small;\r
84   border-top: 2px solid silver;\r
85   padding-top: 0.5em;\r
86   margin-top: 4.0em;\r
87 }\r
88 div#footer-text {\r
89   float: left;\r
90   padding-bottom: 0.5em;\r
91 }\r
92 div#footer-badges {\r
93   float: right;\r
94   padding-bottom: 0.5em;\r
95 }\r
96 \r
97 div#preamble,\r
98 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,\r
99 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,\r
100 div.admonitionblock {\r
101   margin-right: 10%;\r
102   margin-top: 1.5em;\r
103   margin-bottom: 1.5em;\r
104 }\r
105 div.admonitionblock {\r
106   margin-top: 2.5em;\r
107   margin-bottom: 2.5em;\r
108 }\r
109 \r
110 div.content { /* Block element content. */\r
111   padding: 0;\r
112 }\r
113 \r
114 /* Block element titles. */\r
115 div.title, caption.title {\r
116   font-family: sans-serif;\r
117   font-weight: bold;\r
118   text-align: left;\r
119   margin-top: 1.0em;\r
120   margin-bottom: 0.5em;\r
121 }\r
122 div.title + * {\r
123   margin-top: 0;\r
124 }\r
125 \r
126 td div.title:first-child {\r
127   margin-top: 0.0em;\r
128 }\r
129 div.content div.title:first-child {\r
130   margin-top: 0.0em;\r
131 }\r
132 div.content + div.title {\r
133   margin-top: 0.0em;\r
134 }\r
135 \r
136 div.sidebarblock > div.content {\r
137   background: #ffffee;\r
138   border: 1px solid silver;\r
139   padding: 0.5em;\r
140 }\r
141 \r
142 div.listingblock > div.content {\r
143   border: 1px solid silver;\r
144   background: #f4f4f4;\r
145   padding: 0.5em;\r
146 }\r
147 \r
148 div.quoteblock > div.content {\r
149   padding-left: 2.0em;\r
150 }\r
151 div.quoteblock .attribution {\r
152   text-align: right;\r
153 }\r
154 \r
155 div.admonitionblock .icon {\r
156   vertical-align: top;\r
157   font-size: 1.1em;\r
158   font-weight: bold;\r
159   text-decoration: underline;\r
160   color: #527bbd;\r
161   padding-right: 0.5em;\r
162 }\r
163 div.admonitionblock td.content {\r
164   padding-left: 0.5em;\r
165   border-left: 2px solid silver;\r
166 }\r
167 \r
168 div.exampleblock > div.content {\r
169   border-left: 2px solid silver;\r
170   padding: 0.5em;\r
171 }\r
172 \r
173 div.verseblock div.content {\r
174   white-space: pre;\r
175 }\r
176 \r
177 div.imageblock div.content { padding-left: 0; }\r
178 div.imageblock img { border: 1px solid silver; }\r
179 span.image img { border-style: none; }\r
180 \r
181 dl {\r
182   margin-top: 0.8em;\r
183   margin-bottom: 0.8em;\r
184 }\r
185 dt {\r
186   margin-top: 0.5em;\r
187   margin-bottom: 0;\r
188   font-style: italic;\r
189 }\r
190 dd > *:first-child {\r
191   margin-top: 0;\r
192 }\r
193 \r
194 ul, ol {\r
195     list-style-position: outside;\r
196 }\r
197 ol.olist2 {\r
198   list-style-type: lower-alpha;\r
199 }\r
200 \r
201 div.tableblock > table {\r
202   border-color: #527bbd;\r
203   border-width: 3px;\r
204 }\r
205 thead {\r
206   font-family: sans-serif;\r
207   font-weight: bold;\r
208 }\r
209 tfoot {\r
210   font-weight: bold;\r
211 }\r
212 \r
213 div.hlist {\r
214   margin-top: 0.8em;\r
215   margin-bottom: 0.8em;\r
216 }\r
217 td.hlist1 {\r
218   vertical-align: top;\r
219   font-style: italic;\r
220   padding-right: 0.8em;\r
221 }\r
222 td.hlist2 {\r
223   vertical-align: top;\r
224 }\r
225 \r
226 @media print {\r
227   div#footer-badges { display: none; }\r
228 }\r
229 include::./stylesheets/xhtml11-manpage.css[]\r
230 /* Workarounds for IE6's broken and incomplete CSS2. */\r
231 \r
232 div.sidebar-content {\r
233   background: #ffffee;\r
234   border: 1px solid silver;\r
235   padding: 0.5em;\r
236 }\r
237 div.sidebar-title, div.image-title {\r
238   font-family: sans-serif;\r
239   font-weight: bold;\r
240   margin-top: 0.0em;\r
241   margin-bottom: 0.5em;\r
242 }\r
243 \r
244 div.listingblock div.content {\r
245   border: 1px solid silver;\r
246   background: #f4f4f4;\r
247   padding: 0.5em;\r
248 }\r
249 \r
250 div.quoteblock-content {\r
251   padding-left: 2.0em;\r
252 }\r
253 \r
254 div.exampleblock-content {\r
255   border-left: 2px solid silver;\r
256   padding-left: 0.5em;\r
257 }\r
258 </style>\r
259 <title>git-read-tree(1)</title>\r
260 </head>\r
261 <body>\r
262 <div id="header">\r
263 <h1>\r
264 git-read-tree(1) Manual Page\r
265 </h1>\r
266 <h2>NAME</h2>\r
267 <div class="sectionbody">\r
268 <p>git-read-tree -\r
269    Reads tree information into the index\r
270 </p>\r
271 </div>\r
272 </div>\r
273 <h2>SYNOPSIS</h2>\r
274 <div class="sectionbody">\r
275 <p><em>git-read-tree</em> (&lt;tree-ish&gt; | [[-m | --reset] [-u | -i]] &lt;tree-ish1&gt; [&lt;tree-ish2&gt; [&lt;tree-ish3&gt;]])</p>\r
276 </div>\r
277 <h2>DESCRIPTION</h2>\r
278 <div class="sectionbody">\r
279 <p>Reads the tree information given by &lt;tree-ish&gt; into the index,\r
280 but does not actually <strong>update</strong> any of the files it "caches". (see:\r
281 <a href="git-checkout-index.html">git-checkout-index(1)</a>)</p>\r
282 <p>Optionally, it can merge a tree into the index, perform a\r
283 fast-forward (i.e. 2-way) merge, or a 3-way merge, with the <tt>-m</tt>\r
284 flag.  When used with <tt>-m</tt>, the <tt>-u</tt> flag causes it to also update\r
285 the files in the work tree with the result of the merge.</p>\r
286 <p>Trivial merges are done by <tt>git-read-tree</tt> itself.  Only conflicting paths\r
287 will be in unmerged state when <tt>git-read-tree</tt> returns.</p>\r
288 </div>\r
289 <h2>OPTIONS</h2>\r
290 <div class="sectionbody">\r
291 <dl>\r
292 <dt>\r
293 -m\r
294 </dt>\r
295 <dd>\r
296 <p>\r
297         Perform a merge, not just a read.  The command will\r
298         refuse to run if your index file has unmerged entries,\r
299         indicating that you have not finished previous merge you\r
300         started.\r
301 </p>\r
302 </dd>\r
303 <dt>\r
304 --reset\r
305 </dt>\r
306 <dd>\r
307 <p>\r
308         Same as -m, except that unmerged entries are discarded\r
309         instead of failing.\r
310 </p>\r
311 </dd>\r
312 <dt>\r
313 -u\r
314 </dt>\r
315 <dd>\r
316 <p>\r
317         After a successful merge, update the files in the work\r
318         tree with the result of the merge.\r
319 </p>\r
320 </dd>\r
321 <dt>\r
322 -i\r
323 </dt>\r
324 <dd>\r
325 <p>\r
326         Usually a merge requires the index file as well as the\r
327         files in the working tree are up to date with the\r
328         current head commit, in order not to lose local\r
329         changes.  This flag disables the check with the working\r
330         tree and is meant to be used when creating a merge of\r
331         trees that are not directly related to the current\r
332         working tree status into a temporary index file.\r
333 </p>\r
334 </dd>\r
335 <dt>\r
336 &lt;tree-ish#&gt;\r
337 </dt>\r
338 <dd>\r
339 <p>\r
340         The id of the tree object(s) to be read/merged.\r
341 </p>\r
342 </dd>\r
343 </dl>\r
344 </div>\r
345 <h2>Merging</h2>\r
346 <div class="sectionbody">\r
347 <p>If <tt>-m</tt> is specified, <tt>git-read-tree</tt> can perform 3 kinds of\r
348 merge, a single tree merge if only 1 tree is given, a\r
349 fast-forward merge with 2 trees, or a 3-way merge if 3 trees are\r
350 provided.</p>\r
351 <h3>Single Tree Merge</h3>\r
352 <p>If only 1 tree is specified, git-read-tree operates as if the user did not\r
353 specify <tt>-m</tt>, except that if the original index has an entry for a\r
354 given pathname, and the contents of the path matches with the tree\r
355 being read, the stat info from the index is used. (In other words, the\r
356 index's stat()s take precedence over the merged tree's).</p>\r
357 <p>That means that if you do a <tt>git-read-tree -m &lt;newtree&gt;</tt> followed by a\r
358 <tt>git-checkout-index -f -u -a</tt>, the <tt>git-checkout-index</tt> only checks out\r
359 the stuff that really changed.</p>\r
360 <p>This is used to avoid unnecessary false hits when <tt>git-diff-files</tt> is\r
361 run after <tt>git-read-tree</tt>.</p>\r
362 <h3>Two Tree Merge</h3>\r
363 <p>Typically, this is invoked as <tt>git-read-tree -m $H $M</tt>, where $H\r
364 is the head commit of the current repository, and $M is the head\r
365 of a foreign tree, which is simply ahead of $H (i.e. we are in a\r
366 fast forward situation).</p>\r
367 <p>When two trees are specified, the user is telling git-read-tree\r
368 the following:</p>\r
369 <ol>\r
370 <li>\r
371 <p>\r
372 The current index and work tree is derived from $H, but\r
373         the user may have local changes in them since $H;\r
374 </p>\r
375 </li>\r
376 <li>\r
377 <p>\r
378 The user wants to fast-forward to $M.\r
379 </p>\r
380 </li>\r
381 </ol>\r
382 <p>In this case, the <tt>git-read-tree -m $H $M</tt> command makes sure\r
383 that no local change is lost as the result of this "merge".\r
384 Here are the "carry forward" rules:</p>\r
385 <div class="literalblock">\r
386 <div class="content">\r
387 <pre><tt>  I (index)           H        M        Result\r
388  -------------------------------------------------------\r
389 0 nothing             nothing  nothing  (does not happen)\r
390 1 nothing             nothing  exists   use M\r
391 2 nothing             exists   nothing  remove path from index\r
392 3 nothing             exists   exists   use M</tt></pre>\r
393 </div></div>\r
394 <div class="literalblock">\r
395 <div class="content">\r
396 <pre><tt>  clean I==H  I==M\r
397  ------------------\r
398 4 yes   N/A   N/A     nothing  nothing  keep index\r
399 5 no    N/A   N/A     nothing  nothing  keep index</tt></pre>\r
400 </div></div>\r
401 <div class="literalblock">\r
402 <div class="content">\r
403 <pre><tt>6 yes   N/A   yes     nothing  exists   keep index\r
404 7 no    N/A   yes     nothing  exists   keep index\r
405 8 yes   N/A   no      nothing  exists   fail\r
406 9 no    N/A   no      nothing  exists   fail</tt></pre>\r
407 </div></div>\r
408 <div class="literalblock">\r
409 <div class="content">\r
410 <pre><tt>10 yes   yes   N/A     exists   nothing  remove path from index\r
411 11 no    yes   N/A     exists   nothing  fail\r
412 12 yes   no    N/A     exists   nothing  fail\r
413 13 no    no    N/A     exists   nothing  fail</tt></pre>\r
414 </div></div>\r
415 <div class="literalblock">\r
416 <div class="content">\r
417 <pre><tt>   clean (H=M)\r
418   ------\r
419 14 yes                 exists   exists   keep index\r
420 15 no                  exists   exists   keep index</tt></pre>\r
421 </div></div>\r
422 <div class="literalblock">\r
423 <div class="content">\r
424 <pre><tt>   clean I==H  I==M (H!=M)\r
425   ------------------\r
426 16 yes   no    no      exists   exists   fail\r
427 17 no    no    no      exists   exists   fail\r
428 18 yes   no    yes     exists   exists   keep index\r
429 19 no    no    yes     exists   exists   keep index\r
430 20 yes   yes   no      exists   exists   use M\r
431 21 no    yes   no      exists   exists   fail</tt></pre>\r
432 </div></div>\r
433 <p>In all "keep index" cases, the index entry stays as in the\r
434 original index file.  If the entry were not up to date,\r
435 git-read-tree keeps the copy in the work tree intact when\r
436 operating under the -u flag.</p>\r
437 <p>When this form of git-read-tree returns successfully, you can\r
438 see what "local changes" you made are carried forward by running\r
439 <tt>git-diff-index --cached $M</tt>.  Note that this does not\r
440 necessarily match <tt>git-diff-index --cached $H</tt> would have\r
441 produced before such a two tree merge.  This is because of cases\r
442 18 and 19 --- if you already had the changes in $M (e.g. maybe\r
443 you picked it up via e-mail in a patch form), <tt>git-diff-index\r
444 --cached $H</tt> would have told you about the change before this\r
445 merge, but it would not show in <tt>git-diff-index --cached $M</tt>\r
446 output after two-tree merge.</p>\r
447 <h3>3-Way Merge</h3>\r
448 <p>Each "index" entry has two bits worth of "stage" state. stage 0 is the\r
449 normal one, and is the only one you'd see in any kind of normal use.</p>\r
450 <p>However, when you do <tt>git-read-tree</tt> with three trees, the "stage"\r
451 starts out at 1.</p>\r
452 <p>This means that you can do</p>\r
453 <div class="listingblock">\r
454 <div class="content">\r
455 <pre><tt>$ git-read-tree -m &lt;tree1&gt; &lt;tree2&gt; &lt;tree3&gt;</tt></pre>\r
456 </div></div>\r
457 <p>and you will end up with an index with all of the &lt;tree1&gt; entries in\r
458 "stage1", all of the &lt;tree2&gt; entries in "stage2" and all of the\r
459 &lt;tree3&gt; entries in "stage3".  When performing a merge of another\r
460 branch into the current branch, we use the common ancestor tree\r
461 as &lt;tree1&gt;, the current branch head as &lt;tree2&gt;, and the other\r
462 branch head as &lt;tree3&gt;.</p>\r
463 <p>Furthermore, <tt>git-read-tree</tt> has special-case logic that says: if you see\r
464 a file that matches in all respects in the following states, it\r
465 "collapses" back to "stage0":</p>\r
466 <ul>\r
467 <li>\r
468 <p>\r
469 stage 2 and 3 are the same; take one or the other (it makes no\r
470      difference - the same work has been done on our branch in\r
471      stage 2 and their branch in stage 3)\r
472 </p>\r
473 </li>\r
474 <li>\r
475 <p>\r
476 stage 1 and stage 2 are the same and stage 3 is different; take\r
477      stage 3 (our branch in stage 2 did not do anything since the\r
478      ancestor in stage 1 while their branch in stage 3 worked on\r
479      it)\r
480 </p>\r
481 </li>\r
482 <li>\r
483 <p>\r
484 stage 1 and stage 3 are the same and stage 2 is different take\r
485      stage 2 (we did something while they did nothing)\r
486 </p>\r
487 </li>\r
488 </ul>\r
489 <p>The <tt>git-write-tree</tt> command refuses to write a nonsensical tree, and it\r
490 will complain about unmerged entries if it sees a single entry that is not\r
491 stage 0.</p>\r
492 <p>Ok, this all sounds like a collection of totally nonsensical rules,\r
493 but it's actually exactly what you want in order to do a fast\r
494 merge. The different stages represent the "result tree" (stage 0, aka\r
495 "merged"), the original tree (stage 1, aka "orig"), and the two trees\r
496 you are trying to merge (stage 2 and 3 respectively).</p>\r
497 <p>The order of stages 1, 2 and 3 (hence the order of three\r
498 &lt;tree-ish&gt; command line arguments) are significant when you\r
499 start a 3-way merge with an index file that is already\r
500 populated.  Here is an outline of how the algorithm works:</p>\r
501 <ul>\r
502 <li>\r
503 <p>\r
504 if a file exists in identical format in all three trees, it will\r
505   automatically collapse to "merged" state by git-read-tree.\r
506 </p>\r
507 </li>\r
508 <li>\r
509 <p>\r
510 a file that has _any_ difference what-so-ever in the three trees\r
511   will stay as separate entries in the index. It's up to "porcelain\r
512   policy" to determine how to remove the non-0 stages, and insert a\r
513   merged version.\r
514 </p>\r
515 </li>\r
516 <li>\r
517 <p>\r
518 the index file saves and restores with all this information, so you\r
519   can merge things incrementally, but as long as it has entries in\r
520   stages 1/2/3 (ie "unmerged entries") you can't write the result. So\r
521   now the merge algorithm ends up being really simple:\r
522 </p>\r
523 <ul>\r
524 <li>\r
525 <p>\r
526 you walk the index in order, and ignore all entries of stage 0,\r
527     since they've already been done.\r
528 </p>\r
529 </li>\r
530 <li>\r
531 <p>\r
532 if you find a "stage1", but no matching "stage2" or "stage3", you\r
533     know it's been removed from both trees (it only existed in the\r
534     original tree), and you remove that entry.\r
535 </p>\r
536 </li>\r
537 <li>\r
538 <p>\r
539 if you find a matching "stage2" and "stage3" tree, you remove one\r
540     of them, and turn the other into a "stage0" entry. Remove any\r
541     matching "stage1" entry if it exists too.  .. all the normal\r
542     trivial rules ..\r
543 </p>\r
544 </li>\r
545 </ul>\r
546 </li>\r
547 </ul>\r
548 <p>You would normally use <tt>git-merge-index</tt> with supplied\r
549 <tt>git-merge-one-file</tt> to do this last step.  The script updates\r
550 the files in the working tree as it merges each path and at the\r
551 end of a successful merge.</p>\r
552 <p>When you start a 3-way merge with an index file that is already\r
553 populated, it is assumed that it represents the state of the\r
554 files in your work tree, and you can even have files with\r
555 changes unrecorded in the index file.  It is further assumed\r
556 that this state is "derived" from the stage 2 tree.  The 3-way\r
557 merge refuses to run if it finds an entry in the original index\r
558 file that does not match stage 2.</p>\r
559 <p>This is done to prevent you from losing your work-in-progress\r
560 changes, and mixing your random changes in an unrelated merge\r
561 commit.  To illustrate, suppose you start from what has been\r
562 commited last to your repository:</p>\r
563 <div class="listingblock">\r
564 <div class="content">\r
565 <pre><tt>$ JC=`git-rev-parse --verify "HEAD^0"`\r
566 $ git-checkout-index -f -u -a $JC</tt></pre>\r
567 </div></div>\r
568 <p>You do random edits, without running git-update-index.  And then\r
569 you notice that the tip of your "upstream" tree has advanced\r
570 since you pulled from him:</p>\r
571 <div class="listingblock">\r
572 <div class="content">\r
573 <pre><tt>$ git-fetch git://.... linus\r
574 $ LT=`cat .git/FETCH_HEAD`</tt></pre>\r
575 </div></div>\r
576 <p>Your work tree is still based on your HEAD ($JC), but you have\r
577 some edits since.  Three-way merge makes sure that you have not\r
578 added or modified index entries since $JC, and if you haven't,\r
579 then does the right thing.  So with the following sequence:</p>\r
580 <div class="listingblock">\r
581 <div class="content">\r
582 <pre><tt>$ git-read-tree -m -u `git-merge-base $JC $LT` $JC $LT\r
583 $ git-merge-index git-merge-one-file -a\r
584 $ echo "Merge with Linus" | \\r
585   git-commit-tree `git-write-tree` -p $JC -p $LT</tt></pre>\r
586 </div></div>\r
587 <p>what you would commit is a pure merge between $JC and $LT without\r
588 your work-in-progress changes, and your work tree would be\r
589 updated to the result of the merge.</p>\r
590 <p>However, if you have local changes in the working tree that\r
591 would be overwritten by this merge,<tt>git-read-tree</tt> will refuse\r
592 to run to prevent your changes from being lost.</p>\r
593 <p>In other words, there is no need to worry about what exists only\r
594 in the working tree.  When you have local changes in a part of\r
595 the project that is not involved in the merge, your changes do\r
596 not interfere with the merge, and are kept intact.  When they\r
597 <strong>do</strong> interfere, the merge does not even start (<tt>git-read-tree</tt>\r
598 complains loudly and fails without modifying anything).  In such\r
599 a case, you can simply continue doing what you were in the\r
600 middle of doing, and when your working tree is ready (i.e. you\r
601 have finished your work-in-progress), attempt the merge again.</p>\r
602 </div>\r
603 <h2>See Also</h2>\r
604 <div class="sectionbody">\r
605 <p><a href="git-write-tree.html">git-write-tree(1)</a>; <a href="git-ls-files.html">git-ls-files(1)</a></p>\r
606 </div>\r
607 <h2>Author</h2>\r
608 <div class="sectionbody">\r
609 <p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p>\r
610 </div>\r
611 <h2>Documentation</h2>\r
612 <div class="sectionbody">\r
613 <p>Documentation by David Greaves, Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p>\r
614 </div>\r
615 <h2>GIT</h2>\r
616 <div class="sectionbody">\r
617 <p>Part of the <a href="git.html">git(7)</a> suite</p>\r
618 </div>\r
619 <div id="footer">\r
620 <div id="footer-text">\r
621 Last updated 27-Dec-2005 00:16:31 PDT\r
622 </div>\r
623 </div>\r
624 </body>\r
625 </html>\r