What 'switch' uses to load a different tree into the index.
git read-tree loads one or more tree objects into the index. It is the low-level engine porcelain like switch, checkout, and merge calls to swap what the staging area thinks the tree looks like.
The index is a flat manifest. read-tree rewrites that manifest from a tree (1-tree mode), fast-forwards it (2-tree mode), or runs a 3-way merge of common-ancestor + ours + theirs (3-tree mode).
git read-tree [--reset] [-u] [-i] [--prefix=<dir>/]
[-m [--aggressive]] [--no-sparse-checkout]
<tree-ish> [<tree-ish> [<tree-ish>]]
1 tree-ish: replace index. 2 tree-ish: fast-forward. 3 tree-ish: merge.| Flag | What it does |
|---|---|
--reset | ⚠️ Replace index unconditionally; discard unmerged entries and local index changes. |
-u | Also update the working tree to match (otherwise WT is left stale). |
--prefix=<dir>/ | Read the tree into a subdirectory; index must be empty under that path. |
-i | Do not refresh stat-cache; useful when WT will not be touched. |
-m | Perform a merge (requires 2 or 3 tree-ish args). |
--aggressive | Resolve trivial 3-way cases (one side unchanged) automatically. |
--no-sparse-checkout | Ignore sparse-checkout patterns for this read. |
git read-tree HEAD).git read-tree HEADgit read-tree --reset -u HEADgit read-tree --prefix=vendor/foo/ <tree-sha>git read-tree -m --aggressive $base $ours $theirs-u whenever the working tree should follow the index, otherwise expect 'modified' noise.--aggressive for scripted merges; it disposes of the boring trivial conflicts.git switch / git restore -- read-tree is a power tool.-u, the working tree is NOT updated -- git status will look chaotic.--reset silently throws away unmerged index entries; you can lose conflict resolutions.--prefix requires that nothing already exists in the index at that path.Hit each option, then Check answers. Score is recorded; Next is always open.