Featured image of post Git checkout, restore y switch: Diferencias y cuándo usar cada unoFeatured image of post Git checkout, restore y switch: Diferencias y cuándo usar cada uno

Git checkout, restore y switch: Diferencias y cuándo usar cada uno

Understand cleaner command definitions: git switch to swap active branches, and git restore to discard unstaged modifications.

Git 2.23 introdujo git switch y git restore para reemplazar los usos sobrecargados de git checkout. Cada comando tiene una responsabilidad única.

git switch

Cambia de rama. Equivalente a git checkout <rama>. -c crea y cambia a una nueva rama. - vuelve a la rama anterior.

git restore

Restaura archivos del working tree o staging. git restore archivo descarta cambios locales. --staged quita archivos del staging.

git checkout (legacy)

Aún funciona pero es sobrecargado. Puede cambiar ramas o restaurar archivos. Para scripts y automatización, prefiere switch y restore.

Migración

Cambia tu memoria muscular: checkout <branch>switch <branch>. checkout -- <file>restore <file>. El comportamiento es idéntico.

Última actualización 2026/07/12 04:12 JST