Início·Comandos de terminal
Publicidade

Garanta seu bônus em uma corretora de cripto

Bônus que você recebe só por se cadastrar. As condições são as que cada corretora anuncia.

git checkout

git

Uso

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

O comando antigo que troca de branch e restaura arquivos, dividido em switch e restore no git 2.23; checkout -- <arquivo> apaga de vez as edições não commitadas.

Opções comuns

OpçãoSignificado
-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

Exemplos

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

O confuso é que desfazer tem várias formas: mover para onde um branch aponta não é o mesmo que criar um commit que reverte.

Como ler

  • Os colchetes [ ] marcam uma parte que você pode omitir.
  • As reticências … indicam que você pode listar vários.
  • As opções diferenciam maiúsculas: em alguns comandos -r e -R fazem coisas diferentes.

Perguntas

QO que git checkout faz?

O comando antigo que troca de branch e restaura arquivos, dividido em switch e restore no git 2.23; checkout -- <arquivo> apaga de vez as edições não commitadas.

QComo se digita?

git checkout <branch> | git checkout -b <new> | git checkout -- <file> — os colchetes marcam o que você pode omitir.

QQuantas opções vale a pena saber?

Aqui estão 6; a lista completa está em man git. Este comando fica em git.

Comandos relacionados

página man: man git-checkout