table example
[git/mjg.git] / Documentation / git-read-tree.1
blob61f7686560bfe5f846c4ca1143b0cb83e58d9a50
1 '\" t
2 .\"     Title: git-read-tree
3 .\"    Author: [see the "Author" section]
4 .\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
5 .\"      Date: 04/30/2010
6 .\"    Manual: Git Manual
7 .\"    Source: Git 1.7.1.1.g16e90.dirty
8 .\"  Language: English
9 .\"
10 .TH "GIT\-READ\-TREE" "1" "04/30/2010" "Git 1\&.7\&.1\&.1\&.g16e90\&.d" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * set default formatting
13 .\" -----------------------------------------------------------------
14 .\" disable hyphenation
15 .nh
16 .\" disable justification (adjust text to left margin only)
17 .ad l
18 .\" -----------------------------------------------------------------
19 .\" * MAIN CONTENT STARTS HERE *
20 .\" -----------------------------------------------------------------
21 .SH "NAME"
22 git-read-tree \- Reads tree information into the index
23 .SH "SYNOPSIS"
24 .sp
25 \fIgit read\-tree\fR [[\-m [\-\-trivial] [\-\-aggressive] | \-\-reset | \-\-prefix=<prefix>] [\-u [\-\-exclude\-per\-directory=<gitignore>] | \-i]] [\-\-index\-output=<file>] [\-\-no\-sparse\-checkout] <tree\-ish1> [<tree\-ish2> [<tree\-ish3>]]
26 .SH "DESCRIPTION"
27 .sp
28 Reads the tree information given by <tree\-ish> into the index, but does not actually \fBupdate\fR any of the files it "caches"\&. (see: \fBgit-checkout-index\fR(1))
29 .sp
30 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\&.
31 .sp
32 Trivial merges are done by \fIgit read\-tree\fR itself\&. Only conflicting paths will be in unmerged state when \fIgit read\-tree\fR returns\&.
33 .SH "OPTIONS"
34 .PP
35 \-m
36 .RS 4
37 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\&.
38 .RE
39 .PP
40 \-\-reset
41 .RS 4
42 Same as \-m, except that unmerged entries are discarded instead of failing\&.
43 .RE
44 .PP
45 \-u
46 .RS 4
47 After a successful merge, update the files in the work tree with the result of the merge\&.
48 .RE
49 .PP
50 \-i
51 .RS 4
52 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\&.
53 .RE
54 .PP
55 \-v
56 .RS 4
57 Show the progress of checking files out\&.
58 .RE
59 .PP
60 \-\-trivial
61 .RS 4
62 Restrict three\-way merge by
63 \fIgit read\-tree\fR
64 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\&.
65 .RE
66 .PP
67 \-\-aggressive
68 .RS 4
69 Usually a three\-way merge by
70 \fIgit read\-tree\fR
71 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:
72 .sp
73 .RS 4
74 .ie n \{\
75 \h'-04'\(bu\h'+03'\c
76 .\}
77 .el \{\
78 .sp -1
79 .IP \(bu 2.3
80 .\}
81 when one side removes a path and the other side leaves the path unmodified\&. The resolution is to remove that path\&.
82 .RE
83 .sp
84 .RS 4
85 .ie n \{\
86 \h'-04'\(bu\h'+03'\c
87 .\}
88 .el \{\
89 .sp -1
90 .IP \(bu 2.3
91 .\}
92 when both sides remove a path\&. The resolution is to remove that path\&.
93 .RE
94 .sp
95 .RS 4
96 .ie n \{\
97 \h'-04'\(bu\h'+03'\c
98 .\}
99 .el \{\
100 .sp -1
101 .IP \(bu 2.3
103 when both sides adds a path identically\&. The resolution is to add that path\&.
107 \-\-prefix=<prefix>/
108 .RS 4
109 Keep the current index contents, and read the contents of named tree\-ish under directory at
110 <prefix>\&. The original index file cannot have anything at the path
111 <prefix>
112 itself, and have nothing in
113 <prefix>/
114 directory\&. Note that the
115 <prefix>/
116 value must end with a slash\&.
119 \-\-exclude\-per\-directory=<gitignore>
120 .RS 4
121 When running the command with
125 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
126 make
127 but before running
128 make clean
129 to remove the generated file\&. This option tells the command to read per\-directory exclude file (usually
130 \fI\&.gitignore\fR) and allows such an untracked but explicitly ignored file to be overwritten\&.
133 \-\-index\-output=<file>
134 .RS 4
135 Instead of writing the results out to
136 $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 rename(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\&.
139 \-\-no\-sparse\-checkout
140 .RS 4
141 Disable sparse checkout support even if
142 core\&.sparseCheckout
143 is true\&.
146 <tree\-ish#>
147 .RS 4
148 The id of the tree object(s) to be read/merged\&.
150 .SH "MERGING"
152 If \-m is specified, \fIgit read\-tree\fR 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\&.
153 .SS "Single Tree Merge"
155 If only 1 tree is specified, \fIgit read\-tree\fR 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 index\(cqs stat()s take precedence over the merged tree\(cqs)\&.
157 That means that if you do a git read\-tree \-m <newtree> followed by a git checkout\-index \-f \-u \-a, the \fIgit checkout\-index\fR only checks out the stuff that really changed\&.
159 This is used to avoid unnecessary false hits when \fIgit diff\-files\fR is run after \fIgit read\-tree\fR\&.
160 .SS "Two Tree Merge"
162 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)\&.
164 When two trees are specified, the user is telling \fIgit read\-tree\fR the following:
166 .RS 4
167 .ie n \{\
168 \h'-04' 1.\h'+01'\c
170 .el \{\
171 .sp -1
172 .IP "  1." 4.2
174 The current index and work tree is derived from $H, but the user may have local changes in them since $H\&.
177 .RS 4
178 .ie n \{\
179 \h'-04' 2.\h'+01'\c
181 .el \{\
182 .sp -1
183 .IP "  2." 4.2
185 The user wants to fast\-forward to $M\&.
188 In this case, the git read\-tree \-m $H $M command makes sure that no local change is lost as the result of this "merge"\&. Here are the "carry forward" rules, where "I" denotes the index, "clean" means that index and work tree coincide, and "exists"/"nothing" refer to the presence of a path in the specified commit:
190 allbox tab(:);
191 lt lt lt lt lt
192 lt lt lt lt lt
193 lt lt lt lt lt
194 lt lt lt lt lt
195 lt lt lt lt lt
196 ^ lt ^ lt ^.
199 T}:T{
202 T}:T{
205 T}:T{
208 T}:T{
210 Result
215 T}:T{
217 nothing
218 T}:T{
220 nothing
221 T}:T{
223 nothing
224 T}:T{
226 (does not happen)
231 T}:T{
233 nothing
234 T}:T{
236 nothing
237 T}:T{
239 exists
240 T}:T{
242 use M
247 T}:T{
249 nothing
250 T}:T{
252 exists
253 T}:T{
255 nothing
256 T}:T{
258 remove path from index
263 T}:T{
265 nothing
266 T}:T{
268 exists
269 T}:T{
271 exists, H ==M
272 T}:T{
274 use M if "initial checkout", keep index otherwise
278 exists, H != M
279 T}::T{
281 fail
284 .sp 1
286 .if n \{\
287 .RS 4
290    clean I==H  I==M
291   \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
292 4  yes   N/A   N/A     nothing  nothing  keep index
293 5  no    N/A   N/A     nothing  nothing  keep index
295 .if n \{\
299 .if n \{\
300 .RS 4
303 6  yes   N/A   yes     nothing  exists   keep index
304 7  no    N/A   yes     nothing  exists   keep index
305 8  yes   N/A   no      nothing  exists   fail
306 9  no    N/A   no      nothing  exists   fail
308 .if n \{\
312 .if n \{\
313 .RS 4
316 10 yes   yes   N/A     exists   nothing  remove path from index
317 11 no    yes   N/A     exists   nothing  fail
318 12 yes   no    N/A     exists   nothing  fail
319 13 no    no    N/A     exists   nothing  fail
321 .if n \{\
325 .if n \{\
326 .RS 4
329    clean (H==M)
330   \-\-\-\-\-\-
331 14 yes                 exists   exists   keep index
332 15 no                  exists   exists   keep index
334 .if n \{\
338 .if n \{\
339 .RS 4
342    clean I==H  I==M (H!=M)
343   \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
344 16 yes   no    no      exists   exists   fail
345 17 no    no    no      exists   exists   fail
346 18 yes   no    yes     exists   exists   keep index
347 19 no    no    yes     exists   exists   keep index
348 20 yes   yes   no      exists   exists   use M
349 21 no    yes   no      exists   exists   fail
351 .if n \{\
355 In all "keep index" cases, the index entry stays as in the original index file\&. If the entry is not up to date, \fIgit read\-tree\fR keeps the copy in the work tree intact when operating under the \-u flag\&.
357 When this form of \fIgit read\-tree\fR returns successfully, you can see which of the "local changes" 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\&.
359 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\&.
360 .SS "3\-Way Merge"
362 Each "index" entry has two bits worth of "stage" state\&. stage 0 is the normal one, and is the only one you\(cqd see in any kind of normal use\&.
364 However, when you do \fIgit read\-tree\fR with three trees, the "stage" starts out at 1\&.
366 This means that you can do
368 .if n \{\
369 .RS 4
372 $ git read\-tree \-m <tree1> <tree2> <tree3>
374 .if n \{\
379 and you will end up with an index with all of the <tree1> entries in "stage1", all of the <tree2> entries in "stage2" and all of the <tree3> entries in "stage3"\&. When performing a merge of another branch into the current branch, we use the common ancestor tree as <tree1>, the current branch head as <tree2>, and the other branch head as <tree3>\&.
381 Furthermore, \fIgit read\-tree\fR has special\-case logic that says: if you see a file that matches in all respects in the following states, it "collapses" back to "stage0":
383 .RS 4
384 .ie n \{\
385 \h'-04'\(bu\h'+03'\c
387 .el \{\
388 .sp -1
389 .IP \(bu 2.3
391 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)
394 .RS 4
395 .ie n \{\
396 \h'-04'\(bu\h'+03'\c
398 .el \{\
399 .sp -1
400 .IP \(bu 2.3
402 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)
405 .RS 4
406 .ie n \{\
407 \h'-04'\(bu\h'+03'\c
409 .el \{\
410 .sp -1
411 .IP \(bu 2.3
413 stage 1 and stage 3 are the same and stage 2 is different take stage 2 (we did something while they did nothing)
416 The \fIgit write\-tree\fR 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\&.
418 OK, this all sounds like a collection of totally nonsensical rules, but it\(cqs actually exactly what you want in order to do a fast merge\&. The different stages represent the "result tree" (stage 0, aka "merged"), the original tree (stage 1, aka "orig"), and the two trees you are trying to merge (stage 2 and 3 respectively)\&.
420 The order of stages 1, 2 and 3 (hence the order of three <tree\-ish> 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:
422 .RS 4
423 .ie n \{\
424 \h'-04'\(bu\h'+03'\c
426 .el \{\
427 .sp -1
428 .IP \(bu 2.3
430 if a file exists in identical format in all three trees, it will automatically collapse to "merged" state by
431 \fIgit read\-tree\fR\&.
434 .RS 4
435 .ie n \{\
436 \h'-04'\(bu\h'+03'\c
438 .el \{\
439 .sp -1
440 .IP \(bu 2.3
442 a file that has
443 \fIany\fR
444 difference what\-so\-ever in the three trees will stay as separate entries in the index\&. It\(cqs up to "porcelain policy" to determine how to remove the non\-0 stages, and insert a merged version\&.
447 .RS 4
448 .ie n \{\
449 \h'-04'\(bu\h'+03'\c
451 .el \{\
452 .sp -1
453 .IP \(bu 2.3
455 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\&., "unmerged entries") you can\(cqt write the result\&. So now the merge algorithm ends up being really simple:
457 .RS 4
458 .ie n \{\
459 \h'-04'\(bu\h'+03'\c
461 .el \{\
462 .sp -1
463 .IP \(bu 2.3
465 you walk the index in order, and ignore all entries of stage 0, since they\(cqve already been done\&.
468 .RS 4
469 .ie n \{\
470 \h'-04'\(bu\h'+03'\c
472 .el \{\
473 .sp -1
474 .IP \(bu 2.3
476 if you find a "stage1", but no matching "stage2" or "stage3", you know it\(cqs been removed from both trees (it only existed in the original tree), and you remove that entry\&.
479 .RS 4
480 .ie n \{\
481 \h'-04'\(bu\h'+03'\c
483 .el \{\
484 .sp -1
485 .IP \(bu 2.3
487 if you find a matching "stage2" and "stage3" tree, you remove one of them, and turn the other into a "stage0" entry\&. Remove any matching "stage1" entry if it exists too\&. \&.\&. all the normal trivial rules \&.\&.
491 You would normally use \fIgit merge\-index\fR with supplied \fIgit merge\-one\-file\fR 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\&.
493 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 "derived" 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\&.
495 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:
497 .if n \{\
498 .RS 4
501 $ JC=`git rev\-parse \-\-verify "HEAD^0"`
502 $ git checkout\-index \-f \-u \-a $JC
504 .if n \{\
509 You do random edits, without running \fIgit update\-index\fR\&. And then you notice that the tip of your "upstream" tree has advanced since you pulled from him:
511 .if n \{\
512 .RS 4
515 $ git fetch git://\&.\&.\&.\&. linus
516 $ LT=`cat \&.git/FETCH_HEAD`
518 .if n \{\
523 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 haven\(cqt, then does the right thing\&. So with the following sequence:
525 .if n \{\
526 .RS 4
529 $ git read\-tree \-m \-u `git merge\-base $JC $LT` $JC $LT
530 $ git merge\-index git\-merge\-one\-file \-a
531 $ echo "Merge with Linus" | \e
532   git commit\-tree `git write\-tree` \-p $JC \-p $LT
534 .if n \{\
539 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\&.
541 However, if you have local changes in the working tree that would be overwritten by this merge, \fIgit read\-tree\fR will refuse to run to prevent your changes from being lost\&.
543 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 \fBdo\fR interfere, the merge does not even start (\fIgit read\-tree\fR 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\&.
544 .SH "SPARSE CHECKOUT"
546 "Sparse checkout" allows to sparsely populate working directory\&. It uses skip\-worktree bit (see \fBgit-update-index\fR(1)) to tell Git whether a file on working directory is worth looking at\&.
548 "git read\-tree" and other merge\-based commands ("git merge", "git checkout"\&...) 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 "git read\-tree" 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\&.
550 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\&.
552 While $GIT_DIR/info/sparse\-checkout is usually used to specify what files are in\&. You can also specify what files are \fInot\fR in, using negate patterns\&. For example, to remove file "unwanted":
554 .if n \{\
555 .RS 4
559 !unwanted
561 .if n \{\
566 Another tricky thing is fully repopulating working directory when you no longer want sparse checkout\&. You cannot just disable "sparse checkout" 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:
568 .if n \{\
569 .RS 4
574 .if n \{\
579 Then you can disable sparse checkout\&. Sparse checkout support in "git read\-tree" and similar commands is disabled by default\&. You need to turn core\&.sparseCheckout on in order to have sparse checkout support\&.
580 .SH "SEE ALSO"
582 \fBgit-write-tree\fR(1); \fBgit-ls-files\fR(1); \fBgitignore\fR(5)
583 .SH "AUTHOR"
585 Written by Linus Torvalds <\m[blue]\fBtorvalds@osdl\&.org\fR\m[]\&\s-2\u[1]\d\s+2>
586 .SH "DOCUMENTATION"
588 Documentation by David Greaves, Junio C Hamano and the git\-list <\m[blue]\fBgit@vger\&.kernel\&.org\fR\m[]\&\s-2\u[2]\d\s+2>\&.
589 .SH "GIT"
591 Part of the \fBgit\fR(1) suite
592 .SH "NOTES"
593 .IP " 1." 4
594 torvalds@osdl.org
595 .RS 4
596 \%mailto:torvalds@osdl.org
598 .IP " 2." 4
599 git@vger.kernel.org
600 .RS 4
601 \%mailto:git@vger.kernel.org