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">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8" />
6 <meta name=
"generator" content=
"AsciiDoc 8.4.5" />
7 <title>git-read-tree(
1)
</title>
8 <style type=
"text/css">
10 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
12 border: 1px solid red;
17 margin: 1em 5% 1em 5%;
22 text-decoration: underline
;
42 h1
, h2
, h3
, h4
, h5
, h6
{
44 font-family: sans-serif
;
51 border-bottom: 2px solid silver
;
69 border: 1px solid silver
;
88 font-family: sans-serif
;
94 span#revnumber
, span#revdate
, span#revremark
{
95 font-family: sans-serif
;
99 font-family: sans-serif
;
101 border-top: 2px solid silver
;
107 padding-bottom: 0.5em;
111 padding-bottom: 0.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
{
122 margin-bottom: 1.5em;
124 div
.admonitionblock
{
126 margin-bottom: 2.5em;
129 div
.content
{ /* Block element content. */
133 /* Block element titles. */
134 div
.title
, caption
.title
{
136 font-family: sans-serif
;
140 margin-bottom: 0.5em;
146 td div
.title:first-child
{
149 div
.content div
.title:first-child
{
152 div
.content
+ div
.title
{
156 div
.sidebarblock
> div
.content
{
158 border: 1px solid silver
;
162 div
.listingblock
> div
.content
{
163 border: 1px solid silver
;
172 div
.quoteblock
> div
.attribution
{
181 div
.verseblock
> div
.content
{
184 div
.verseblock
> div
.attribution
{
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div
.verseblock
+ div
.attribution
{
193 div
.admonitionblock
.icon
{
197 text-decoration: underline
;
199 padding-right: 0.5em;
201 div
.admonitionblock td
.content
{
203 border-left: 2px solid silver
;
206 div
.exampleblock
> div
.content
{
207 border-left: 2px solid silver
;
211 div
.imageblock div
.content
{ padding-left: 0; }
212 span
.image img
{ border-style: none
; }
213 a
.image:visited
{ color: white
; }
217 margin-bottom: 0.8em;
230 list-style-position: outside
;
233 list-style-type: decimal
;
236 list-style-type: lower-alpha
;
239 list-style-type: upper-alpha
;
242 list-style-type: lower-roman
;
245 list-style-type: upper-roman
;
248 div
.compact ul
, div
.compact ol
,
249 div
.compact p
, div
.compact p
,
250 div
.compact div
, div
.compact div
{
252 margin-bottom: 0.1em;
255 div
.tableblock
> table
{
256 border: 3px solid
#527bbd;
259 font-family: sans-serif
;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div
.tableblock
> table
[frame
="void"] {
275 div
.tableblock
> table
[frame
="hsides"] {
276 border-left-style: none
;
277 border-right-style: none
;
279 div
.tableblock
> table
[frame
="vsides"] {
280 border-top-style: none
;
281 border-bottom-style: none
;
287 margin-bottom: 0.8em;
290 padding-bottom: 15px;
292 dt
.hdlist1
.strong
, td
.hdlist1
.strong
{
298 padding-right: 0.8em;
304 div
.hdlist
.compact tr
{
314 div#footer-badges
{ display: none
; }
319 font-family: sans-serif
;
323 margin-bottom: 0.1em;
326 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
342 /* Overrides for manpage documents */
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver
;
347 border-bottom: 2px solid silver
;
357 div#toc
{ display: none
; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div
.sidebar-content
{
364 border: 1px solid silver
;
367 div
.sidebar-title
, div
.image-title
{
369 font-family: sans-serif
;
372 margin-bottom: 0.5em;
375 div
.listingblock div
.content
{
376 border: 1px solid silver
;
381 div
.quoteblock-attribution
{
386 div
.verseblock-content
{
389 div
.verseblock-attribution
{
394 div
.exampleblock-content
{
395 border-left: 2px solid silver
;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc
a:visited
{ color: blue
; }
406 git-read-tree(
1) Manual Page
409 <div class=
"sectionbody">
411 Reads tree information into the index
415 <h2 id=
"_synopsis">SYNOPSIS
</h2>
416 <div class=
"sectionbody">
417 <div class=
"paragraph"><p><em>git read-tree
</em> [[-m [--trivial] [--aggressive] | --reset | --prefix=
<prefix
>]
418 [-u [--exclude-per-directory=
<gitignore
>] | -i]]
419 [--index-output=
<file
>] [--no-sparse-checkout]
420 (--empty |
<tree-ish1
> [
<tree-ish2
> [
<tree-ish3
>]])
</p></div>
422 <h2 id=
"_description">DESCRIPTION
</h2>
423 <div class=
"sectionbody">
424 <div class=
"paragraph"><p>Reads the tree information given by
<tree-ish
> into the index,
425 but does not actually
<strong>update
</strong> any of the files it
"caches". (see:
426 <a href=
"git-checkout-index.html">git-checkout-index(
1)
</a>)
</p></div>
427 <div class=
"paragraph"><p>Optionally, it can merge a tree into the index, perform a
428 fast-forward (i.e.
2-way) merge, or a
3-way merge, with the
<tt>-m
</tt>
429 flag. When used with
<tt>-m
</tt>, the
<tt>-u
</tt> flag causes it to also update
430 the files in the work tree with the result of the merge.
</p></div>
431 <div class=
"paragraph"><p>Trivial merges are done by
<em>git read-tree
</em> itself. Only conflicting paths
432 will be in unmerged state when
<em>git read-tree
</em> returns.
</p></div>
434 <h2 id=
"_options">OPTIONS
</h2>
435 <div class=
"sectionbody">
436 <div class=
"dlist"><dl>
442 Perform a merge, not just a read. The command will
443 refuse to run if your index file has unmerged entries,
444 indicating that you have not finished previous merge you
453 Same as -m, except that unmerged entries are discarded
462 After a successful merge, update the files in the work
463 tree with the result of the merge.
471 Usually a merge requires the index file as well as the
472 files in the working tree are up to date with the
473 current head commit, in order not to lose local
474 changes. This flag disables the check with the working
475 tree and is meant to be used when creating a merge of
476 trees that are not directly related to the current
477 working tree status into a temporary index file.
485 Show the progress of checking files out.
493 Restrict three-way merge by
<em>git read-tree
</em> to happen
494 only if there is no file-level merging required, instead
495 of resolving merge for trivial cases and leaving
496 conflicting files unresolved in the index.
504 Usually a three-way merge by
<em>git read-tree
</em> resolves
505 the merge for really trivial cases and leaves other
506 cases unresolved in the index, so that Porcelains can
507 implement different merge policies. This flag makes the
508 command to resolve a few more cases internally:
510 <div class=
"ulist"><ul>
513 when one side removes a path and the other side leaves the path
514 unmodified. The resolution is to remove that path.
519 when both sides remove a path. The resolution is to remove that path.
524 when both sides adds a path identically. The resolution
531 --prefix=
<prefix
>/
535 Keep the current index contents, and read the contents
536 of named tree-ish under directory at
<tt><prefix
></tt>. The
537 original index file cannot have anything at the path
538 <tt><prefix
></tt> itself, and have nothing in
<tt><prefix
>/
</tt>
539 directory. Note that the
<tt><prefix
>/
</tt> value must end
544 --exclude-per-directory=
<gitignore
>
548 When running the command with
<tt>-u
</tt> and
<tt>-m
</tt> options, the
549 merge result may need to overwrite paths that are not
550 tracked in the current branch. The command usually
551 refuses to proceed with the merge to avoid losing such a
552 path. However this safety valve sometimes gets in the
553 way. For example, it often happens that the other
554 branch added a file that used to be a generated file in
555 your branch, and the safety valve triggers when you try
556 to switch to that branch after you ran
<tt>make
</tt> but before
557 running
<tt>make clean
</tt> to remove the generated file. This
558 option tells the command to read per-directory exclude
559 file (usually
<em>.gitignore
</em>) and allows such an untracked
560 but explicitly ignored file to be overwritten.
564 --index-output=
<file
>
568 Instead of writing the results out to
<tt>$GIT_INDEX_FILE
</tt>,
569 write the resulting index in the named file. While the
570 command is operating, the original index file is locked
571 with the same mechanism as usual. The file must allow
572 to be rename(
2)ed into from a temporary file that is
573 created next to the usual index file; typically this
574 means it needs to be on the same filesystem as the index
575 file itself, and you need write permission to the
576 directories the index file and index output file are
585 Disable sparse checkout support even if
<tt>core.sparseCheckout
</tt>
594 Instead of reading tree object(s) into the index, just empty
603 The id of the tree object(s) to be read/merged.
608 <h2 id=
"_merging">Merging
</h2>
609 <div class=
"sectionbody">
610 <div class=
"paragraph"><p>If
<tt>-m
</tt> is specified,
<em>git read-tree
</em> can perform
3 kinds of
611 merge, a single tree merge if only
1 tree is given, a
612 fast-forward merge with
2 trees, or a
3-way merge if
3 trees are
614 <h3 id=
"_single_tree_merge">Single Tree Merge
</h3><div style=
"clear:left"></div>
615 <div class=
"paragraph"><p>If only
1 tree is specified,
<em>git read-tree
</em> operates as if the user did not
616 specify
<tt>-m
</tt>, except that if the original index has an entry for a
617 given pathname, and the contents of the path match with the tree
618 being read, the stat info from the index is used. (In other words, the
619 index
’s stat()s take precedence over the merged tree
’s).
</p></div>
620 <div class=
"paragraph"><p>That means that if you do a
<tt>git read-tree -m
<newtree
></tt> followed by a
621 <tt>git checkout-index -f -u -a
</tt>, the
<em>git checkout-index
</em> only checks out
622 the stuff that really changed.
</p></div>
623 <div class=
"paragraph"><p>This is used to avoid unnecessary false hits when
<em>git diff-files
</em> is
624 run after
<em>git read-tree
</em>.
</p></div>
625 <h3 id=
"_two_tree_merge">Two Tree Merge
</h3><div style=
"clear:left"></div>
626 <div class=
"paragraph"><p>Typically, this is invoked as
<tt>git read-tree -m $H $M
</tt>, where $H
627 is the head commit of the current repository, and $M is the head
628 of a foreign tree, which is simply ahead of $H (i.e. we are in a
629 fast-forward situation).
</p></div>
630 <div class=
"paragraph"><p>When two trees are specified, the user is telling
<em>git read-tree
</em>
631 the following:
</p></div>
632 <div class=
"olist arabic"><ol class=
"arabic">
635 The current index and work tree is derived from $H, but
636 the user may have local changes in them since $H.
641 The user wants to fast-forward to $M.
645 <div class=
"paragraph"><p>In this case, the
<tt>git read-tree -m $H $M
</tt> command makes sure
646 that no local change is lost as the result of this
"merge".
647 Here are the
"carry forward" rules, where
"I" denotes the index,
648 "clean" means that index and work tree coincide, and
"exists"/
"nothing"
649 refer to the presence of a path in the specified commit:
</p></div>
650 <div class=
"literalblock">
651 <div class=
"content">
652 <pre><tt> I H M Result
653 -------------------------------------------------------
654 0 nothing nothing nothing (does not happen)
655 1 nothing nothing exists use M
656 2 nothing exists nothing remove path from index
657 3 nothing exists exists, use M if
"initial checkout",
658 H == M keep index otherwise
662 <div class=
"literalblock">
663 <div class=
"content">
664 <pre><tt> clean I==H I==M
666 4 yes N/A N/A nothing nothing keep index
667 5 no N/A N/A nothing nothing keep index
</tt></pre>
669 <div class=
"literalblock">
670 <div class=
"content">
671 <pre><tt>6 yes N/A yes nothing exists keep index
672 7 no N/A yes nothing exists keep index
673 8 yes N/A no nothing exists fail
674 9 no N/A no nothing exists fail
</tt></pre>
676 <div class=
"literalblock">
677 <div class=
"content">
678 <pre><tt>10 yes yes N/A exists nothing remove path from index
679 11 no yes N/A exists nothing fail
680 12 yes no N/A exists nothing fail
681 13 no no N/A exists nothing fail
</tt></pre>
683 <div class=
"literalblock">
684 <div class=
"content">
685 <pre><tt> clean (H==M)
687 14 yes exists exists keep index
688 15 no exists exists keep index
</tt></pre>
690 <div class=
"literalblock">
691 <div class=
"content">
692 <pre><tt> clean I==H I==M (H!=M)
694 16 yes no no exists exists fail
695 17 no no no exists exists fail
696 18 yes no yes exists exists keep index
697 19 no no yes exists exists keep index
698 20 yes yes no exists exists use M
699 21 no yes no exists exists fail
</tt></pre>
701 <div class=
"paragraph"><p>In all
"keep index" cases, the index entry stays as in the
702 original index file. If the entry is not up to date,
703 <em>git read-tree
</em> keeps the copy in the work tree intact when
704 operating under the -u flag.
</p></div>
705 <div class=
"paragraph"><p>When this form of
<em>git read-tree
</em> returns successfully, you can
706 see which of the
"local changes" that you made were carried forward by running
707 <tt>git diff-index --cached $M
</tt>. Note that this does not
708 necessarily match what
<tt>git diff-index --cached $H
</tt> would have
709 produced before such a two tree merge. This is because of cases
710 18 and
19 --- if you already had the changes in $M (e.g. maybe
711 you picked it up via e-mail in a patch form),
<tt>git diff-index
712 --cached $H
</tt> would have told you about the change before this
713 merge, but it would not show in
<tt>git diff-index --cached $M
</tt>
714 output after the two-tree merge.
</p></div>
715 <div class=
"paragraph"><p>Case
3 is slightly tricky and needs explanation. The result from this
716 rule logically should be to remove the path if the user staged the removal
717 of the path and then switching to a new branch. That however will prevent
718 the initial checkout from happening, so the rule is modified to use M (new
719 tree) only when the content of the index is empty. Otherwise the removal
720 of the path is kept as long as $H and $M are the same.
</p></div>
721 <h3 id=
"_3_way_merge">3-Way Merge
</h3><div style=
"clear:left"></div>
722 <div class=
"paragraph"><p>Each
"index" entry has two bits worth of
"stage" state. stage
0 is the
723 normal one, and is the only one you
’d see in any kind of normal use.
</p></div>
724 <div class=
"paragraph"><p>However, when you do
<em>git read-tree
</em> with three trees, the
"stage"
725 starts out at
1.
</p></div>
726 <div class=
"paragraph"><p>This means that you can do
</p></div>
727 <div class=
"listingblock">
728 <div class=
"content">
729 <pre><tt>$ git read-tree -m
<tree1
> <tree2
> <tree3
></tt></pre>
731 <div class=
"paragraph"><p>and you will end up with an index with all of the
<tree1
> entries in
732 "stage1", all of the
<tree2
> entries in
"stage2" and all of the
733 <tree3
> entries in
"stage3". When performing a merge of another
734 branch into the current branch, we use the common ancestor tree
735 as
<tree1
>, the current branch head as
<tree2
>, and the other
736 branch head as
<tree3
>.
</p></div>
737 <div class=
"paragraph"><p>Furthermore,
<em>git read-tree
</em> has special-case logic that says: if you see
738 a file that matches in all respects in the following states, it
739 "collapses" back to
"stage0":
</p></div>
740 <div class=
"ulist"><ul>
743 stage
2 and
3 are the same; take one or the other (it makes no
744 difference - the same work has been done on our branch in
745 stage
2 and their branch in stage
3)
750 stage
1 and stage
2 are the same and stage
3 is different; take
751 stage
3 (our branch in stage
2 did not do anything since the
752 ancestor in stage
1 while their branch in stage
3 worked on
758 stage
1 and stage
3 are the same and stage
2 is different take
759 stage
2 (we did something while they did nothing)
763 <div class=
"paragraph"><p>The
<em>git write-tree
</em> command refuses to write a nonsensical tree, and it
764 will complain about unmerged entries if it sees a single entry that is not
766 <div class=
"paragraph"><p>OK, this all sounds like a collection of totally nonsensical rules,
767 but it
’s actually exactly what you want in order to do a fast
768 merge. The different stages represent the
"result tree" (stage
0, aka
769 "merged"), the original tree (stage
1, aka
"orig"), and the two trees
770 you are trying to merge (stage
2 and
3 respectively).
</p></div>
771 <div class=
"paragraph"><p>The order of stages
1,
2 and
3 (hence the order of three
772 <tree-ish
> command line arguments) are significant when you
773 start a
3-way merge with an index file that is already
774 populated. Here is an outline of how the algorithm works:
</p></div>
775 <div class=
"ulist"><ul>
778 if a file exists in identical format in all three trees, it will
779 automatically collapse to
"merged" state by
<em>git read-tree
</em>.
784 a file that has
<em>any
</em> difference what-so-ever in the three trees
785 will stay as separate entries in the index. It
’s up to
"porcelain
786 policy" to determine how to remove the non-
0 stages, and insert a
792 the index file saves and restores with all this information, so you
793 can merge things incrementally, but as long as it has entries in
794 stages
1/
2/
3 (i.e.,
"unmerged entries") you can
’t write the result. So
795 now the merge algorithm ends up being really simple:
797 <div class=
"ulist"><ul>
800 you walk the index in order, and ignore all entries of stage
0,
801 since they
’ve already been done.
806 if you find a
"stage1", but no matching
"stage2" or
"stage3", you
807 know it
’s been removed from both trees (it only existed in the
808 original tree), and you remove that entry.
813 if you find a matching
"stage2" and
"stage3" tree, you remove one
814 of them, and turn the other into a
"stage0" entry. Remove any
815 matching
"stage1" entry if it exists too. .. all the normal
822 <div class=
"paragraph"><p>You would normally use
<em>git merge-index
</em> with supplied
823 <em>git merge-one-file
</em> to do this last step. The script updates
824 the files in the working tree as it merges each path and at the
825 end of a successful merge.
</p></div>
826 <div class=
"paragraph"><p>When you start a
3-way merge with an index file that is already
827 populated, it is assumed that it represents the state of the
828 files in your work tree, and you can even have files with
829 changes unrecorded in the index file. It is further assumed
830 that this state is
"derived" from the stage
2 tree. The
3-way
831 merge refuses to run if it finds an entry in the original index
832 file that does not match stage
2.
</p></div>
833 <div class=
"paragraph"><p>This is done to prevent you from losing your work-in-progress
834 changes, and mixing your random changes in an unrelated merge
835 commit. To illustrate, suppose you start from what has been
836 committed last to your repository:
</p></div>
837 <div class=
"listingblock">
838 <div class=
"content">
839 <pre><tt>$ JC=`git rev-parse --verify
"HEAD^0"`
840 $ git checkout-index -f -u -a $JC
</tt></pre>
842 <div class=
"paragraph"><p>You do random edits, without running
<em>git update-index
</em>. And then
843 you notice that the tip of your
"upstream" tree has advanced
844 since you pulled from him:
</p></div>
845 <div class=
"listingblock">
846 <div class=
"content">
847 <pre><tt>$ git fetch git://.... linus
848 $ LT=`cat .git/FETCH_HEAD`
</tt></pre>
850 <div class=
"paragraph"><p>Your work tree is still based on your HEAD ($JC), but you have
851 some edits since. Three-way merge makes sure that you have not
852 added or modified index entries since $JC, and if you haven
’t,
853 then does the right thing. So with the following sequence:
</p></div>
854 <div class=
"listingblock">
855 <div class=
"content">
856 <pre><tt>$ git read-tree -m -u `git merge-base $JC $LT` $JC $LT
857 $ git merge-index git-merge-one-file -a
858 $ echo
"Merge with Linus" | \
859 git commit-tree `git write-tree` -p $JC -p $LT
</tt></pre>
861 <div class=
"paragraph"><p>what you would commit is a pure merge between $JC and $LT without
862 your work-in-progress changes, and your work tree would be
863 updated to the result of the merge.
</p></div>
864 <div class=
"paragraph"><p>However, if you have local changes in the working tree that
865 would be overwritten by this merge,
<em>git read-tree
</em> will refuse
866 to run to prevent your changes from being lost.
</p></div>
867 <div class=
"paragraph"><p>In other words, there is no need to worry about what exists only
868 in the working tree. When you have local changes in a part of
869 the project that is not involved in the merge, your changes do
870 not interfere with the merge, and are kept intact. When they
871 <strong>do
</strong> interfere, the merge does not even start (
<em>git read-tree
</em>
872 complains loudly and fails without modifying anything). In such
873 a case, you can simply continue doing what you were in the
874 middle of doing, and when your working tree is ready (i.e. you
875 have finished your work-in-progress), attempt the merge again.
</p></div>
877 <h2 id=
"_sparse_checkout">Sparse checkout
</h2>
878 <div class=
"sectionbody">
879 <div class=
"paragraph"><p>"Sparse checkout" allows to sparsely populate working directory.
880 It uses skip-worktree bit (see
<a href=
"git-update-index.html">git-update-index(
1)
</a>) to tell
881 Git whether a file on working directory is worth looking at.
</p></div>
882 <div class=
"paragraph"><p>"git read-tree" and other merge-based commands (
"git merge",
"git
883 checkout"…) can help maintaining skip-worktree bitmap and working
884 directory update.
<tt>$GIT_DIR/info/sparse-checkout
</tt> is used to
885 define the skip-worktree reference bitmap. When
"git read-tree" needs
886 to update working directory, it will reset skip-worktree bit in index
887 based on this file, which uses the same syntax as .gitignore files.
888 If an entry matches a pattern in this file, skip-worktree will be
889 set on that entry. Otherwise, skip-worktree will be unset.
</p></div>
890 <div class=
"paragraph"><p>Then it compares the new skip-worktree value with the previous one. If
891 skip-worktree turns from unset to set, it will add the corresponding
892 file back. If it turns from set to unset, that file will be removed.
</p></div>
893 <div class=
"paragraph"><p>While
<tt>$GIT_DIR/info/sparse-checkout
</tt> is usually used to specify what
894 files are in. You can also specify what files are
<em>not
</em> in, using
895 negate patterns. For example, to remove file
"unwanted":
</p></div>
896 <div class=
"listingblock">
897 <div class=
"content">
901 <div class=
"paragraph"><p>Another tricky thing is fully repopulating working directory when you
902 no longer want sparse checkout. You cannot just disable
"sparse
903 checkout" because skip-worktree are still in the index and you working
904 directory is still sparsely populated. You should re-populate working
905 directory with the
<tt>$GIT_DIR/info/sparse-checkout
</tt> file content as
907 <div class=
"listingblock">
908 <div class=
"content">
909 <pre><tt>*
</tt></pre>
911 <div class=
"paragraph"><p>Then you can disable sparse checkout. Sparse checkout support in
"git
912 read-tree" and similar commands is disabled by default. You need to
913 turn
<tt>core.sparseCheckout
</tt> on in order to have sparse checkout
916 <h2 id=
"_see_also">SEE ALSO
</h2>
917 <div class=
"sectionbody">
918 <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>;
919 <a href=
"gitignore.html">gitignore(
5)
</a></p></div>
921 <h2 id=
"_git">GIT
</h2>
922 <div class=
"sectionbody">
923 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
926 <div id=
"footer-text">
927 Last updated
2011-
03-
15 23:
30:
14 UTC