git cherry-pick
git
쓰는 꼴
git cherry-pick [-x] <commit>...다른 브랜치의 커밋 하나를 지금 브랜치에 복사합니다 — 해시가 새로 생기므로 나중에 그 브랜치를 merge하면 같은 변경이 두 번 보일 수 있습니다.
자주 쓰는 옵션
| 옵션 | 뜻 |
|---|---|
| -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 |
예시
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
되돌리는 방법이 여럿이라 헷갈립니다 — 가리키는 곳을 옮기는 것과 새 커밋을 얹는 것은 다릅니다.
읽는 방법
- 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
- 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
- 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.
자주 묻는 것
Q. git cherry-pick은 무엇을 하나요?
다른 브랜치의 커밋 하나를 지금 브랜치에 복사합니다 — 해시가 새로 생기므로 나중에 그 브랜치를 merge하면 같은 변경이 두 번 보일 수 있습니다.
Q. 어떻게 치나요?
git cherry-pick [-x] <commit>... — 대괄호는 생략할 수 있는 자리입니다.
Q. 옵션은 몇 개나 자주 쓰나요?
여기 정리한 것은 7개입니다. 전체 목록은 man git에 있습니다. 이 명령은 git 갈래입니다.
같이 보는 명령
man 페이지: man git-cherry-pick