Sinopsis
git checkout-index [-a] [-f] [-u] [--prefix=<dir>] [<file>...]
Descripción
El comando git checkout-index es plumbing que copia archivos del index al árbol de trabajo. Es la operación de bajo nivel detrás de git checkout file y partes de git restore.
Usado por scripts que necesitan extraer archivos exactamente como están en el index, o reemplazar archivos del árbol de trabajo con sus versiones del index. Soporta exportar a un prefijo (subdirectorio) con --prefix=.
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. Use it when scripting deployment from the index, building source tarballs, or exporting a snapshot to a directory other than the working tree.
Opciones comunes
| Opción | Descripción |
|---|---|
-a, --all | Check out every file in the index. |
-f, --force | Overwrite existing files. |
-u | Update stat information for files written. |
--prefix=<dir> | Write into <dir> instead of working tree. |
--stage=<n> | Check out a specific stage (1=base, 2=ours, 3=theirs). |
-z | NUL-terminated input/output. |
--no-create | Don't create files; just update stats. |
Ejemplos
git checkout-index -a -f --prefix=/tmp/snapshot/
# Export the entire index to /tmp/snapshot/
git checkout-index --prefix=build/ src/main.c
# Copy a single file into build/
git checkout-index --stage=2 -f -- conflicted.txt
# Pick "ours" version during a conflict
git ls-files | git checkout-index -f --stdin
# Restore every tracked file from the index
Errores comunes
The --prefix argument must end with a slash, otherwise filenames concatenate awkwardly. Without -f, existing files in the destination cause errors. Picking the wrong --stage during conflict resolution applies a worse version than intended.
Comandos relacionados
git checkout, git restore, git archive, git ls-files