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ção | Significado |
|---|---|
| -x | note the original hash in the new message |
| -n | apply and stage without committing |
| -e | edit the message |
| -m <parent> | pick a merge commit, choosing a side |
| <a>..<b> | a range; a itself is not included |
| --continue | go on after a conflict |
| --abort | undo the whole pick |
Exemplos
git cherry-pick a1b2c3dcopies that commit onto the current branch with a new hash
git cherry-pick -x a1b2c3dsame, with the source hash recorded in the message
git cherry-pick a1b2c3d^..d4e5f6acopies 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