Sinopsis
git stash push -p -m <msg> -- <pathspec>
git stash branch <newbranch> [<stash>]
git stash create
git stash store -m <msg> <sha>
Descripción
Más allá del git stash y git stash pop básicos, los flujos avanzados de stash incluyen mensajes nombrados (git stash push -m descripción), stashing parcial con -p, stashear solo cambios staged (--staged), y crear branches desde stashes (git stash branch).
El stash es una pila local que vive en refs/stash. Inspecciona con git stash list, git stash show -p stash@{2}. Los stashes no se pushean automáticamente; son local-only.
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.
Opciones comunes
| Subcommand / Option | Description |
|---|---|
push -p | Stash interactively chosen hunks. |
push -- <pathspec> | Stash only specified paths. |
--keep-index | Stash but keep what's already staged. |
--no-keep-index | Reset index when stashing (default). |
branch <name> | Recreate state on a fresh branch. |
create | Make a stash commit but don't store it. |
store -m | Place an existing commit on the stack. |
Ejemplos
git stash push -p -m "WIP: only refactor changes" -- src/refactor/
# Stash only specific paths, interactively
git stash --keep-index -m "Test pre-staged"
# Verify that staged changes pass tests, with WIP set aside
git stash branch fix-from-stash stash@{2}
# Resurrect a stash that no longer applies cleanly
SHA=$(git stash create "checkpoint")
git stash store -m "manual checkpoint" "$SHA"
# Programmatic stash creation
Errores comunes
Stashing during a merge or rebase mixes states and confuses the stack. Avoid. Long-running stashes outlive their context — review periodically. --keep-index is great for verifying staged changes, but the resulting stash includes both staged and unstaged content, which can surprise.
Comandos relacionados
git stash, git commit --fixup, git worktree, git restore