본문 바로가기
C.W.K.
Stream
Lesson 04 of 05 · published

Cherry-pick과 rerere

~22 min · cherry-pick, rerere

Level 0추적 전 새싹
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Cherry-pick은 골라 가져오고, rerere는 해결을 기억해

다른 branch의 commit 하나만 필요하고 branch 전체를 merge하고 싶지 않을 때 git cherry-pick <hash>를 써. 그 commit의 변경을 현재 branch 위의 새 commit으로 적용해. source commit과는 hash가 다르므로 복사지를 옮기는 일이 아니야. main의 bug fix를 release branch로 backport하거나, 버릴 실험 branch에서 유용한 commit 하나를 건지거나, 오래 나란히 가는 branch 사이에 fix를 전파할 때 좋아.

git cherry-pick A..B는 A 다음부터 B까지의 commit을 순서대로 적용해. conflict가 나면 merge나 rebase처럼 멈추며, 해결하고 git add한 뒤 git cherry-pick --continue해. --abort로 시작 전으로 돌아갈 수도 있어. -x는 message에 "(cherry picked from commit <hash>)"를 붙여 branch를 건넌 변경의 출처를 남겨.

git rerere, 곧 "reuse recorded resolution"은 오래 병렬로 가는 branch가 있는 repo의 숨은 영웅이야. 활성화하면 Git이 conflict 해결을 기록했다가 같은 hunk와 같은 양쪽 내용이 다시 충돌할 때 이전 답을 자동 적용해. main과 주기적으로 merge하는 maintenance branch에서 특히 큰 수고를 아껴. git config --global rerere.enabled true로 켜두면 절약이 조용히 쌓여.

main에서 release branch로 fix 열 개를 backport한다고 해보자. rerere가 없으면 main의 후속 refactor가 같은 줄을 건드릴 때마다 cherry-pick conflict를 다시 풀어야 해. rerere가 켜져 있으면 각 pattern을 한 번만 해결하고 같은 pattern은 자동으로 처리해. git rerere status로 기록 상태를 보고, 저장한 해결이 틀렸다면 git rerere clear로 cache를 비워.

Code

Cherry-pick 기본·bash
# 다른 branch 에서 commit 하나:
git cherry-pick abc1234

# 범위 (A 제외, B 포함):
git cherry-pick A_HASH..B_HASH

# 메시지에 출처 표시 포함:
git cherry-pick -x abc1234

# 자동 commit 건너뛰기 (stage 만):
git cherry-pick -n abc1234

# Conflict 해결 후 재개:
git add resolved-file
git cherry-pick --continue

# 빠지기:
git cherry-pick --abort
Rerere 활성화 + 관찰·bash
# Global (또는 repo 별) 활성화:
git config --global rerere.enabled true

# Conflict 후 해결 + commit. Git 이 조용히 해결 기록.

# 기록된 거 보기:
git rerere status
git rerere diff

# 미래 conflict 자동 해결 시 출력:
#   Resolved 'src/auth.js' using previous resolution.

# 기록된 해결이 틀렸으면 cache wipe:
git rerere clear

External links

Exercise

mainrelease-1.0 branch를 만들고 main에 작은 fix commit을 하나 추가해. git switch release-1.0git cherry-pick -x <fix-hash>를 실행해 cherry-pick된 commit에 출처 줄이 있는지 확인해. 별도로 rerere를 global로 켜고 conflict를 만들어 해결한 다음 다른 branch에서 같은 conflict를 재현해. 두 번째에는 rerere가 자동으로 해결하는지 확인해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.