table example
[git/mjg.git] / Documentation / git-read-tree.1.html
blob8db74e471d367873eaa753b429124d5b700288fe
1 Content-type: text/html
3 <HTML><HEAD><TITLE>Manpage of GIT\-READ\-TREE</TITLE>
4 </HEAD><BODY>
5 <H1>GIT\-READ\-TREE</H1>
6 Section: Git Manual (1)<BR>Updated: 04/30/2010<BR><A HREF="#index">Index</A>
7 <A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR>
19 <A NAME="lbAB">&nbsp;</A>
20 <H2>NAME</H2>
22 git-read-tree - Reads tree information into the index
23 <A NAME="lbAC">&nbsp;</A>
24 <H2>SYNOPSIS</H2>
26 <P>
27 <I>git read-tree</I> [[-m [--trivial] [--aggressive] | --reset | --prefix=&lt;prefix&gt;] [-u [--exclude-per-directory=&lt;gitignore&gt;] | -i]] [--index-output=&lt;file&gt;] [--no-sparse-checkout] &lt;tree-ish1&gt; [&lt;tree-ish2&gt; [&lt;tree-ish3&gt;]]
28 <A NAME="lbAD">&nbsp;</A>
29 <H2>DESCRIPTION</H2>
31 <P>
32 Reads the tree information given by &lt;tree-ish&gt; into the index, but does not actually <B>update</B> any of the files it &quot;caches&quot;. (see: <B><A HREF="http://localhost/cgi-bin/man/man2html?1+git-checkout-index">git-checkout-index</A></B>(1))
33 <P>
34 Optionally, it can merge a tree into the index, perform a fast-forward (i.e. 2-way) merge, or a 3-way merge, with the -m flag. When used with -m, the -u flag causes it to also update the files in the work tree with the result of the merge.
35 <P>
36 Trivial merges are done by <I>git read-tree</I> itself. Only conflicting paths will be in unmerged state when <I>git read-tree</I> returns.
37 <A NAME="lbAE">&nbsp;</A>
38 <H2>OPTIONS</H2>
40 <P>
43 <DL COMPACT><DT><DD>
44 Perform a merge, not just a read. The command will refuse to run if your index file has unmerged entries, indicating that you have not finished previous merge you started.
45 </DL>
47 <P>
49 --reset
50 <DL COMPACT><DT><DD>
51 Same as -m, except that unmerged entries are discarded instead of failing.
52 </DL>
54 <P>
57 <DL COMPACT><DT><DD>
58 After a successful merge, update the files in the work tree with the result of the merge.
59 </DL>
61 <P>
64 <DL COMPACT><DT><DD>
65 Usually a merge requires the index file as well as the files in the working tree are up to date with the current head commit, in order not to lose local changes. This flag disables the check with the working tree and is meant to be used when creating a merge of trees that are not directly related to the current working tree status into a temporary index file.
66 </DL>
68 <P>
71 <DL COMPACT><DT><DD>
72 Show the progress of checking files out.
73 </DL>
75 <P>
77 --trivial
78 <DL COMPACT><DT><DD>
79 Restrict three-way merge by
80 <I>git read-tree</I>
81 to happen only if there is no file-level merging required, instead of resolving merge for trivial cases and leaving conflicting files unresolved in the index.
82 </DL>
84 <P>
86 --aggressive
87 <DL COMPACT><DT><DD>
88 Usually a three-way merge by
89 <I>git read-tree</I>
90 resolves the merge for really trivial cases and leaves other cases unresolved in the index, so that Porcelains can implement different merge policies. This flag makes the command to resolve a few more cases internally:
91 <P>
92 <DL COMPACT><DT><DD>
96 when one side removes a path and the other side leaves the path unmodified. The resolution is to remove that path.
97 </DL>
99 <P>
100 <DL COMPACT><DT><DD>
104 when both sides remove a path. The resolution is to remove that path.
105 </DL>
108 <DL COMPACT><DT><DD>
112 when both sides adds a path identically. The resolution is to add that path.
113 </DL>
115 </DL>
119 --prefix=&lt;prefix&gt;/
120 <DL COMPACT><DT><DD>
121 Keep the current index contents, and read the contents of named tree-ish under directory at
122 &lt;prefix&gt;. The original index file cannot have anything at the path
123 &lt;prefix&gt;
124 itself, and have nothing in
125 &lt;prefix&gt;/
126 directory. Note that the
127 &lt;prefix&gt;/
128 value must end with a slash.
129 </DL>
133 --exclude-per-directory=&lt;gitignore&gt;
134 <DL COMPACT><DT><DD>
135 When running the command with
139 options, the merge result may need to overwrite paths that are not tracked in the current branch. The command usually refuses to proceed with the merge to avoid losing such a path. However this safety valve sometimes gets in the way. For example, it often happens that the other branch added a file that used to be a generated file in your branch, and the safety valve triggers when you try to switch to that branch after you ran
140 make
141 but before running
142 make clean
143 to remove the generated file. This option tells the command to read per-directory exclude file (usually
144 <I>.gitignore</I>) and allows such an untracked but explicitly ignored file to be overwritten.
145 </DL>
149 --index-output=&lt;file&gt;
150 <DL COMPACT><DT><DD>
151 Instead of writing the results out to
152 $GIT_INDEX_FILE, write the resulting index in the named file. While the command is operating, the original index file is locked with the same mechanism as usual. The file must allow to be <A HREF="http://localhost/cgi-bin/man/man2html?2+rename">rename</A>(2)ed into from a temporary file that is created next to the usual index file; typically this means it needs to be on the same filesystem as the index file itself, and you need write permission to the directories the index file and index output file are located in.
153 </DL>
157 --no-sparse-checkout
158 <DL COMPACT><DT><DD>
159 Disable sparse checkout support even if
160 core.sparseCheckout
161 is true.
162 </DL>
166 &lt;tree-ish#&gt;
167 <DL COMPACT><DT><DD>
168 The id of the tree object(s) to be read/merged.
169 </DL>
171 <A NAME="lbAF">&nbsp;</A>
172 <H2>MERGING</H2>
175 If -m is specified, <I>git read-tree</I> can perform 3 kinds of merge, a single tree merge if only 1 tree is given, a fast-forward merge with 2 trees, or a 3-way merge if 3 trees are provided.
176 <A NAME="lbAG">&nbsp;</A>
177 <H3>Single Tree Merge</H3>
180 If only 1 tree is specified, <I>git read-tree</I> operates as if the user did not specify -m, except that if the original index has an entry for a given pathname, and the contents of the path match with the tree being read, the stat info from the index is used. (In other words, the indexcqs stat()s take precedence over the merged treecqs).
182 That means that if you do a git read-tree -m &lt;newtree&gt; followed by a git checkout-index -f -u -a, the <I>git checkout-index</I> only checks out the stuff that really changed.
184 This is used to avoid unnecessary false hits when <I>git diff-files</I> is run after <I>git read-tree</I>.
185 <A NAME="lbAH">&nbsp;</A>
186 <H3>Two Tree Merge</H3>
189 Typically, this is invoked as git read-tree -m $H $M, where $H is the head commit of the current repository, and $M is the head of a foreign tree, which is simply ahead of $H (i.e. we are in a fast-forward situation).
191 When two trees are specified, the user is telling <I>git read-tree</I> the following:
193 <DL COMPACT><DT><DD>
197 The current index and work tree is derived from $H, but the user may have local changes in them since $H.
198 </DL>
201 <DL COMPACT><DT><DD>
205 The user wants to fast-forward to $M.
206 </DL>
209 In this case, the git read-tree -m $H $M command makes sure that no local change is lost as the result of this &quot;merge&quot;. Here are the &quot;carry forward&quot; rules, where &quot;I&quot; denotes the index, &quot;clean&quot; means that index and work tree coincide, and &quot;exists&quot;/&quot;nothing&quot; refer to the presence of a path in the specified commit:
210 <TABLE BORDER>
211 <TR VALIGN=top><TD>
213 </TD><TD>
216 </TD><TD>
219 </TD><TD>
222 </TD><TD>
224 Result
225 <BR></TD></TR>
226 <TR VALIGN=top><TD>
229 </TD><TD>
231 nothing
232 </TD><TD>
234 nothing
235 </TD><TD>
237 nothing
238 </TD><TD>
240 (does not happen)
241 <BR></TD></TR>
242 <TR VALIGN=top><TD>
245 </TD><TD>
247 nothing
248 </TD><TD>
250 nothing
251 </TD><TD>
253 exists
254 </TD><TD>
256 use M
257 <BR></TD></TR>
258 <TR VALIGN=top><TD>
261 </TD><TD>
263 nothing
264 </TD><TD>
266 exists
267 </TD><TD>
269 nothing
270 </TD><TD>
272 remove path from index
273 <BR></TD></TR>
274 <TR VALIGN=top><TD ROWSPAN=2>
277 </TD><TD>
279 nothing
280 </TD><TD ROWSPAN=2>
282 exists
283 </TD><TD>
285 exists, H ==M
286 </TD><TD ROWSPAN=2>
288 use M if &quot;initial checkout&quot;, keep index otherwise
289 <BR></TD></TR>
290 <TR VALIGN=top><TD>
292 exists, H != M
293 </TD><TD>
295 fail
296 </TD></TR>
297 </TABLE>
301 <DL COMPACT><DT><DD>
305 <PRE>
306 clean I==H I==M
307 ------------------
308 4 yes N/A N/A nothing nothing keep index
309 5 no N/A N/A nothing nothing keep index
310 </PRE>
312 </DL>
318 <DL COMPACT><DT><DD>
322 <PRE>
323 6 yes N/A yes nothing exists keep index
324 7 no N/A yes nothing exists keep index
325 8 yes N/A no nothing exists fail
326 9 no N/A no nothing exists fail
327 </PRE>
329 </DL>
335 <DL COMPACT><DT><DD>
339 <PRE>
340 10 yes yes N/A exists nothing remove path from index
341 11 no yes N/A exists nothing fail
342 12 yes no N/A exists nothing fail
343 13 no no N/A exists nothing fail
344 </PRE>
346 </DL>
352 <DL COMPACT><DT><DD>
356 <PRE>
357 clean (H==M)
358 ------
359 14 yes exists exists keep index
360 15 no exists exists keep index
361 </PRE>
363 </DL>
369 <DL COMPACT><DT><DD>
373 <PRE>
374 clean I==H I==M (H!=M)
375 ------------------
376 16 yes no no exists exists fail
377 17 no no no exists exists fail
378 18 yes no yes exists exists keep index
379 19 no no yes exists exists keep index
380 20 yes yes no exists exists use M
381 21 no yes no exists exists fail
382 </PRE>
384 </DL>
390 In all &quot;keep index&quot; cases, the index entry stays as in the original index file. If the entry is not up to date, <I>git read-tree</I> keeps the copy in the work tree intact when operating under the -u flag.
392 When this form of <I>git read-tree</I> returns successfully, you can see which of the &quot;local changes&quot; that you made were carried forward by running git diff-index --cached $M. Note that this does not necessarily match what git diff-index --cached $H would have produced before such a two tree merge. This is because of cases 18 and 19 --- if you already had the changes in $M (e.g. maybe you picked it up via e-mail in a patch form), git diff-index --cached $H would have told you about the change before this merge, but it would not show in git diff-index --cached $M output after the two-tree merge.
394 Case 3 is slightly tricky and needs explanation. The result from this rule logically should be to remove the path if the user staged the removal of the path and then switching to a new branch. That however will prevent the initial checkout from happening, so the rule is modified to use M (new tree) only when the content of the index is empty. Otherwise the removal of the path is kept as long as $H and $M are the same.
395 <A NAME="lbAI">&nbsp;</A>
396 <H3>3-Way Merge</H3>
399 Each &quot;index&quot; entry has two bits worth of &quot;stage&quot; state. stage 0 is the normal one, and is the only one youcqd see in any kind of normal use.
401 However, when you do <I>git read-tree</I> with three trees, the &quot;stage&quot; starts out at 1.
403 This means that you can do
405 <DL COMPACT><DT><DD>
409 <PRE>
410 $ git read-tree -m &lt;tree1&gt; &lt;tree2&gt; &lt;tree3&gt;
411 </PRE>
413 </DL>
420 and you will end up with an index with all of the &lt;tree1&gt; entries in &quot;stage1&quot;, all of the &lt;tree2&gt; entries in &quot;stage2&quot; and all of the &lt;tree3&gt; entries in &quot;stage3&quot;. When performing a merge of another branch into the current branch, we use the common ancestor tree as &lt;tree1&gt;, the current branch head as &lt;tree2&gt;, and the other branch head as &lt;tree3&gt;.
422 Furthermore, <I>git read-tree</I> has special-case logic that says: if you see a file that matches in all respects in the following states, it &quot;collapses&quot; back to &quot;stage0&quot;:
424 <DL COMPACT><DT><DD>
428 stage 2 and 3 are the same; take one or the other (it makes no difference - the same work has been done on our branch in stage 2 and their branch in stage 3)
429 </DL>
432 <DL COMPACT><DT><DD>
436 stage 1 and stage 2 are the same and stage 3 is different; take stage 3 (our branch in stage 2 did not do anything since the ancestor in stage 1 while their branch in stage 3 worked on it)
437 </DL>
440 <DL COMPACT><DT><DD>
444 stage 1 and stage 3 are the same and stage 2 is different take stage 2 (we did something while they did nothing)
445 </DL>
448 The <I>git write-tree</I> command refuses to write a nonsensical tree, and it will complain about unmerged entries if it sees a single entry that is not stage 0.
450 OK, this all sounds like a collection of totally nonsensical rules, but itcqs actually exactly what you want in order to do a fast merge. The different stages represent the &quot;result tree&quot; (stage 0, aka &quot;merged&quot;), the original tree (stage 1, aka &quot;orig&quot;), and the two trees you are trying to merge (stage 2 and 3 respectively).
452 The order of stages 1, 2 and 3 (hence the order of three &lt;tree-ish&gt; command line arguments) are significant when you start a 3-way merge with an index file that is already populated. Here is an outline of how the algorithm works:
454 <DL COMPACT><DT><DD>
458 if a file exists in identical format in all three trees, it will automatically collapse to &quot;merged&quot; state by
459 <I>git read-tree</I>.
460 </DL>
463 <DL COMPACT><DT><DD>
467 a file that has
468 <I>any</I>
469 difference what-so-ever in the three trees will stay as separate entries in the index. Itcqs up to &quot;porcelain policy&quot; to determine how to remove the non-0 stages, and insert a merged version.
470 </DL>
473 <DL COMPACT><DT><DD>
477 the index file saves and restores with all this information, so you can merge things incrementally, but as long as it has entries in stages 1/2/3 (i.e., &quot;unmerged entries&quot;) you cancqt write the result. So now the merge algorithm ends up being really simple:
479 <DL COMPACT><DT><DD>
483 you walk the index in order, and ignore all entries of stage 0, since theycqve already been done.
484 </DL>
487 <DL COMPACT><DT><DD>
491 if you find a &quot;stage1&quot;, but no matching &quot;stage2&quot; or &quot;stage3&quot;, you know itcqs been removed from both trees (it only existed in the original tree), and you remove that entry.
492 </DL>
495 <DL COMPACT><DT><DD>
499 if you find a matching &quot;stage2&quot; and &quot;stage3&quot; tree, you remove one of them, and turn the other into a &quot;stage0&quot; entry. Remove any matching &quot;stage1&quot; entry if it exists too. .. all the normal trivial rules ..
500 </DL>
502 </DL>
505 You would normally use <I>git merge-index</I> with supplied <I>git merge-one-file</I> to do this last step. The script updates the files in the working tree as it merges each path and at the end of a successful merge.
507 When you start a 3-way merge with an index file that is already populated, it is assumed that it represents the state of the files in your work tree, and you can even have files with changes unrecorded in the index file. It is further assumed that this state is &quot;derived&quot; from the stage 2 tree. The 3-way merge refuses to run if it finds an entry in the original index file that does not match stage 2.
509 This is done to prevent you from losing your work-in-progress changes, and mixing your random changes in an unrelated merge commit. To illustrate, suppose you start from what has been committed last to your repository:
511 <DL COMPACT><DT><DD>
515 <PRE>
516 $ JC=`git rev-parse --verify &quot;HEAD^0&quot;`
517 $ git checkout-index -f -u -a $JC
518 </PRE>
520 </DL>
527 You do random edits, without running <I>git update-index</I>. And then you notice that the tip of your &quot;upstream&quot; tree has advanced since you pulled from him:
529 <DL COMPACT><DT><DD>
533 <PRE>
534 $ git fetch <A HREF="git://....">git://....</A> linus
535 $ LT=`cat .git/FETCH_HEAD`
536 </PRE>
538 </DL>
545 Your work tree is still based on your HEAD ($JC), but you have some edits since. Three-way merge makes sure that you have not added or modified index entries since $JC, and if you havencqt, then does the right thing. So with the following sequence:
547 <DL COMPACT><DT><DD>
551 <PRE>
552 $ git read-tree -m -u `git merge-base $JC $LT` $JC $LT
553 $ git merge-index git-merge-one-file -a
554 $ echo &quot;Merge with Linus&quot; | \
555 git commit-tree `git write-tree` -p $JC -p $LT
556 </PRE>
558 </DL>
565 what you would commit is a pure merge between $JC and $LT without your work-in-progress changes, and your work tree would be updated to the result of the merge.
567 However, if you have local changes in the working tree that would be overwritten by this merge, <I>git read-tree</I> will refuse to run to prevent your changes from being lost.
569 In other words, there is no need to worry about what exists only in the working tree. When you have local changes in a part of the project that is not involved in the merge, your changes do not interfere with the merge, and are kept intact. When they <B>do</B> interfere, the merge does not even start (<I>git read-tree</I> complains loudly and fails without modifying anything). In such a case, you can simply continue doing what you were in the middle of doing, and when your working tree is ready (i.e. you have finished your work-in-progress), attempt the merge again.
570 <A NAME="lbAJ">&nbsp;</A>
571 <H2>SPARSE CHECKOUT</H2>
574 &quot;Sparse checkout&quot; allows to sparsely populate working directory. It uses skip-worktree bit (see <B><A HREF="http://localhost/cgi-bin/man/man2html?1+git-update-index">git-update-index</A></B>(1)) to tell Git whether a file on working directory is worth looking at.
576 &quot;git read-tree&quot; and other merge-based commands (&quot;git merge&quot;, &quot;git checkout&quot;...) can help maintaining skip-worktree bitmap and working directory update. $GIT_DIR/info/sparse-checkout is used to define the skip-worktree reference bitmap. When &quot;git read-tree&quot; needs to update working directory, it will reset skip-worktree bit in index based on this file, which uses the same syntax as .gitignore files. If an entry matches a pattern in this file, skip-worktree will be set on that entry. Otherwise, skip-worktree will be unset.
578 Then it compares the new skip-worktree value with the previous one. If skip-worktree turns from unset to set, it will add the corresponding file back. If it turns from set to unset, that file will be removed.
580 While $GIT_DIR/info/sparse-checkout is usually used to specify what files are in. You can also specify what files are <I>not</I> in, using negate patterns. For example, to remove file &quot;unwanted&quot;:
582 <DL COMPACT><DT><DD>
586 <PRE>
588 !unwanted
589 </PRE>
591 </DL>
598 Another tricky thing is fully repopulating working directory when you no longer want sparse checkout. You cannot just disable &quot;sparse checkout&quot; because skip-worktree are still in the index and you working directory is still sparsely populated. You should re-populate working directory with the $GIT_DIR/info/sparse-checkout file content as follows:
600 <DL COMPACT><DT><DD>
604 <PRE>
606 </PRE>
608 </DL>
615 Then you can disable sparse checkout. Sparse checkout support in &quot;git read-tree&quot; and similar commands is disabled by default. You need to turn core.sparseCheckout on in order to have sparse checkout support.
616 <A NAME="lbAK">&nbsp;</A>
617 <H2>SEE ALSO</H2>
620 <B><A HREF="http://localhost/cgi-bin/man/man2html?1+git-write-tree">git-write-tree</A></B>(1); <B><A HREF="http://localhost/cgi-bin/man/man2html?1+git-ls-files">git-ls-files</A></B>(1); <B><A HREF="http://localhost/cgi-bin/man/man2html?5+gitignore">gitignore</A></B>(5)
621 <A NAME="lbAL">&nbsp;</A>
622 <H2>AUTHOR</H2>
625 Written by Linus Torvalds &lt;m[blue]<B><A HREF="mailto:torvalds@osdl.org">torvalds@osdl.org</A></B>m[]<FONT SIZE="-2">[1]</FONT>&gt;
626 <A NAME="lbAM">&nbsp;</A>
627 <H2>DOCUMENTATION</H2>
630 Documentation by David Greaves, Junio C Hamano and the git-list &lt;m[blue]<B><A HREF="mailto:git@vger.kernel.org">git@vger.kernel.org</A></B>m[]<FONT SIZE="-2">[2]</FONT>&gt;.
631 <A NAME="lbAN">&nbsp;</A>
632 <H2>GIT</H2>
635 Part of the <B><A HREF="http://localhost/cgi-bin/man/man2html?1+git">git</A></B>(1) suite
636 <A NAME="lbAO">&nbsp;</A>
637 <H2>NOTES</H2>
639 <DL COMPACT>
640 <DT> 1.<DD>
641 <A HREF="mailto:torvalds@osdl.org">torvalds@osdl.org</A>
642 <DL COMPACT><DT><DD>
643 mailto:<A HREF="mailto:torvalds@osdl.org">torvalds@osdl.org</A>
644 </DL>
646 <DT> 2.<DD>
647 <A HREF="mailto:git@vger.kernel.org">git@vger.kernel.org</A>
648 <DL COMPACT><DT><DD>
649 mailto:<A HREF="mailto:git@vger.kernel.org">git@vger.kernel.org</A>
650 </DL>
653 </DL>
655 <HR>
656 <A NAME="index">&nbsp;</A><H2>Index</H2>
657 <DL>
658 <DT><A HREF="#lbAB">NAME</A><DD>
659 <DT><A HREF="#lbAC">SYNOPSIS</A><DD>
660 <DT><A HREF="#lbAD">DESCRIPTION</A><DD>
661 <DT><A HREF="#lbAE">OPTIONS</A><DD>
662 <DT><A HREF="#lbAF">MERGING</A><DD>
663 <DL>
664 <DT><A HREF="#lbAG">Single Tree Merge</A><DD>
665 <DT><A HREF="#lbAH">Two Tree Merge</A><DD>
666 <DT><A HREF="#lbAI">3-Way Merge</A><DD>
667 </DL>
668 <DT><A HREF="#lbAJ">SPARSE CHECKOUT</A><DD>
669 <DT><A HREF="#lbAK">SEE ALSO</A><DD>
670 <DT><A HREF="#lbAL">AUTHOR</A><DD>
671 <DT><A HREF="#lbAM">DOCUMENTATION</A><DD>
672 <DT><A HREF="#lbAN">GIT</A><DD>
673 <DT><A HREF="#lbAO">NOTES</A><DD>
674 </DL>
675 <HR>
676 This document was created by
677 <A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
678 using the manual pages.<BR>
679 Time: 14:46:23 GMT, April 30, 2010
680 </BODY>
681 </HTML>