Início·Comandos de terminal

git cherry-pick

git

Uso

git cherry-pick [-x] <commit>...

Copia um único commit para o branch atual como um commit novo com outro hash, então mesclar aquele branch depois pode mostrar a mesma mudança duas vezes.

Opções comuns

OpçãoSignificado
-xnote the original hash in the new message
-napply and stage without committing
-eedit the message
-m <parent>pick a merge commit, choosing a side
<a>..<b>a range; a itself is not included
--continuego on after a conflict
--abortundo the whole pick

Exemplos

git cherry-pick a1b2c3d

copies that commit onto the current branch with a new hash

git cherry-pick -x a1b2c3d

same, with the source hash recorded in the message

git cherry-pick a1b2c3d^..d4e5f6a

copies a range, this time including a1b2c3d

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

Q. O que git cherry-pick faz?

Copia um único commit para o branch atual como um commit novo com outro hash, então mesclar aquele branch depois pode mostrar a mesma mudança duas vezes.

Q. Como se digita?

git cherry-pick [-x] <commit>... — os colchetes marcam o que você pode omitir.

Q. Quantas opções vale a pena saber?

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

Comandos relacionados

página man: man git-cherry-pick