Por Anónimo (no verificado) , 29 Abril 2026

Sinopsis

git read-tree [-m | -u | --reset] <tree-ish>...

Descripción

El comando git read-tree es plumbing que carga el contenido de uno o más objetos tree en el index. Es la operación fundamental detrás de git checkout y git merge.

Con un solo tree, reemplaza el index. Con varios, hace una operación tipo merge. Plumbing puro: rara vez se invoca directamente.

En el uso diario, este comando se integra estrechamente con alias de shell, plugins de editor e integración continua. Los usuarios avanzados a menudo añaden alias que combinan los flags que siempre pasan. El formato de salida puede personalizarse vía configuración de Git. Cuando algo sale mal, ejecuta el comando con GIT_TRACE=1 para revelar las llamadas plumbing subyacentes.

Entender cómo este comando interactúa con el resto del modelo de datos de Git rinde dividendos. Cada comando opera sobre algún subconjunto de las piezas (objetos, index, refs, árbol de trabajo), y saber cuáles toca ayuda a predecir resultados y a recuperarse de errores.

Cuándo usar

Most users never need this. It's relevant for implementing custom merge tools, scripts that build the index from arbitrary trees, or for the git read-tree --prefix=<dir> trick to merge a subtree.

Opciones comunes

OpciónDescripción
-mThree-way merge tree mode.
-uUpdate working tree to match index.
--resetBehave like reset --hard for the index.
--prefix=<dir>Read tree into a subdirectory.
--emptyEmpty the index.
-iDon't update working tree.

Ejemplos

git read-tree --empty
# Clear the index

git read-tree HEAD
# Re-populate index from HEAD's tree

git read-tree --prefix=lib/ -u other-branch:src
# Splice the src/ tree of another branch into lib/

git read-tree -m HEAD origin/main
# Merge two trees into the index (low-level merge)

Errores comunes

Calling read-tree without -u leaves the working tree out of sync with the index, surprising subsequent operations. Doing this in a busy worktree can cause confusing diffs.

Comandos relacionados

git write-tree, git checkout, git merge, git update-index