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

Sinopsis

git commit-tree <tree> [-p <parent>]... [-m <msg>] [-S]

Descripción

El comando git commit-tree es plumbing que crea un nuevo objeto commit dado un tree, padres opcionales y un mensaje. Es la operación de bajo nivel que git commit envuelve.

Útil para construir commits sintéticos en scripts: imports de historial, merges personalizados o herramientas de automatización que necesitan crear commits sin pasar por el árbol de trabajo.

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 developers never use this directly. It's a building block for tools that synthesize commits programmatically: importers, custom merge strategies, history-rewriting tools. filter-repo uses commit-tree internally.

Opciones comunes

OpciónDescripción
-p <parent>Specify a parent commit (repeatable for merges).
-m <msg>Commit message (or read stdin).
-F <file>Read message from file.
-S[<keyid>]GPG-sign the commit.

Ejemplos

TREE=$(git write-tree)
COMMIT=$(echo "Initial commit" | git commit-tree "$TREE")
git update-ref refs/heads/main "$COMMIT"
# Build a root commit from scratch

PARENT=$(git rev-parse HEAD)
TREE=$(git write-tree)
COMMIT=$(echo "Custom merge" | git commit-tree "$TREE" -p "$PARENT" -p "feature")
git update-ref refs/heads/main "$COMMIT"
# Synthesize a custom merge commit

Errores comunes

Forgetting to git update-ref leaves the commit dangling — git gc will eventually delete it. Author/committer environment variables (GIT_AUTHOR_NAME etc.) must be set if you want non-default identities.

Comandos relacionados

git write-tree, git update-ref, git commit, git filter-repo