Home Explore Blog CI



git

6th chunk of `Documentation/git-read-tree.adoc`
d827d5aaad44ea5465e3f8e743da59b376bdeca978547b1f0000000100000d8c
 $JC -p $LT
----------------

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.

However, if you have local changes in the working tree that
would be overwritten by this merge, 'git read-tree' will refuse
to run to prevent your changes from being lost.

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
*do* interfere, the merge does not even start ('git read-tree'
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.


SPARSE CHECKOUT
---------------

Note: The skip-worktree capabilities in linkgit:git-update-index[1]
and `read-tree` predated the introduction of
linkgit:git-sparse-checkout[1].  Users are encouraged to use the
`sparse-checkout` command in preference to these plumbing commands for
sparse-checkout/skip-worktree related needs.  However, the information
below might be useful to users trying to understand the pattern style
used in non-cone mode of the `sparse-checkout` command.

"Sparse checkout" allows populating the working directory sparsely.
It uses the skip-worktree bit (see linkgit:git-update-index[1]) to
tell Git whether a file in the working directory is worth looking at.

'git read-tree' and other merge-based commands ('git merge', 'git
checkout'...) can help maintaining the 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 the working directory, it resets the skip-worktree bit in the index
based on this file, which uses the same syntax as .gitignore files.
If an entry matches a pattern in this file, or the entry corresponds to
a file present in the working tree, then skip-worktree will not be
set on that entry. Otherwise, skip-worktree will be set.

Then it compares the new skip-worktree value with the previous one. If
skip-worktree turns from set to unset, it will add the corresponding
file back. If it turns from unset to set, that file will be removed.

While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
files are in, you can also specify what files are _not_ in, using
negate patterns. For example, to remove the file `unwanted`:

----------------
/*
!unwanted
----------------

Another tricky thing is fully repopulating the working directory when you
no longer want sparse checkout. You cannot just disable "sparse
checkout" because skip-worktree bits are still in the index and your working
directory is still sparsely populated. You should re-populate the working
directory with the `$GIT_DIR/info/sparse-checkout` file content as
follows:

----------------
/*
----------------

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.


SEE ALSO
--------
linkgit:git-write-tree[1], linkgit:git-ls-files[1],
linkgit:gitignore[5], linkgit:git-sparse-checkout[1]

GIT
---
Part of the linkgit:git[1] suite

Title: Git Sparse Checkout
Summary
Git's sparse checkout feature allows for populating the working directory sparsely, using the skip-worktree bit to determine which files to consider, and can be managed through the `sparse-checkout` command and `$GIT_DIR/info/sparse-checkout` file, enabling efficient and flexible repository management