Inicio·Comandos de terminal
Publicidad

Consigue tu bono en un exchange de criptomonedas

Bonos que recibes solo por registrarte. Las condiciones son las que publica cada exchange.

git checkout

git

Uso

git checkout <branch> | git checkout -b <new> | git checkout -- <file>

El comando antiguo que cambia de rama y restaura archivos, dividido en switch y restore en git 2.23; checkout -- <archivo> borra para siempre los cambios sin commit.

Opciones habituales

OpciónSignificado
-b <new>create the branch and switch to it
-B <new>create or reset it to the current commit
-- <file>overwrite the file with the staged version, losing your edits
--track <remote>/<branch>start a local branch that follows a remote one
--detachsit on a commit with no branch attached
-fthrow away local changes to switch anyway

Ejemplos

git checkout -b feature/login

branches off the current commit and moves there

git checkout main

switches branch, same as git switch main

git checkout -- src/app.ts

discards uncommitted edits to that file; they are gone

Lo confuso es que deshacer tiene varias formas: mover a dónde apunta una rama no es lo mismo que añadir un commit que la revierte.

Cómo leerlo

  • Los corchetes [ ] marcan una parte que puedes omitir.
  • Los puntos suspensivos … indican que puedes poner varios.
  • Las opciones distinguen mayúsculas: en algunos comandos -r y -R no hacen lo mismo.

Preguntas

Q¿Qué hace git checkout?

El comando antiguo que cambia de rama y restaura archivos, dividido en switch y restore en git 2.23; checkout -- <archivo> borra para siempre los cambios sin commit.

Q¿Cómo se escribe?

git checkout <branch> | git checkout -b <new> | git checkout -- <file> — los corchetes marcan lo que puedes omitir.

Q¿Cuántas opciones vale la pena saber?

Aquí van 6; la lista completa está en man git. Este comando está en git.

Comandos relacionados

página man: man git-checkout