입문서 - 변경을 병합합니다

KoreanTutorialExport에서는, 다른 사람과 변경을 공유하는 방법을 배웠습니다. 여기에서는 Import가 아닌, 서로 다른 저장소들간의 병합을 다루어 봅시다.

먼저, 뭔가 병합할 것을 작성하지 않으면 안됩니다. my-hello 저장소를 한번 더 복제합시다.

$ cd ..
$ hg clone my-hello my-hello-desc

hello.c의 주석 부분에 설명을 덧붙여봅니다.

$ cd my-hello-desc
$ vi hello.c

두번째 줄을 아래와 같이 변경합시다.

 * hello.c

을 이렇게 바꿉니다.

 * hello.c - hello, world

저장한 다음 편집기를 종료하여, 변경을 반영합시다. 이번은 commit 명령에 -m 설정을 써서, 편집기를 띄우지 않게 하여 시간을 절약합니다.:

$ hg commit -m 'Add description of hello.c'

이 시점에서, my-hello-new-output 저장소hello.c에 변경이 한건 있어, my-hello-desc 저장hello.c에 다른 변경이 있습니다. 이들 2개의 분기한 개발 라인을 어떻게 해서 병합할까요? 한쪽에서부터 한쪽으로 pull하고 싶을 때에, 문제가 생기지는 않을까요?

문제 없이 잘 됩니다. my-hello-desc에 있는 채, my-hello-new-output로부터 변경을 끌어오기하여, 무슨 일이 나는지 살펴봅시다:

$ hg pull ../my-hello-new-output
pulling from ../my-hello-new-output
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
(run 'hg heads' to see head, 'hg merge' to merge)

이는 KoreanTutorialShareChangepull의 출력과 완전히 똑같아 보이네요! 그래서 Update도 꼭 해야겠죠?

$ hg update
abort: update spans branches, use 'hg merge' or 'hg update -C' to lose changes

아니, 뭔가 일이 터졌습니다. Mercurial저장소에 가한 변경을 병합할 필요가 있다고 알리고 있습니다. 수고가 좀 들 것 같죠? 실제로는 매우 간단합니다. 출력 마지막 줄의 표시를 따라 보세요:

$ hg merge
merging hello.c
0 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

해야 할 것은 이뿐입니다! Mercurial은 병합을 자동으로 처리할 수 있습니다. hello.c을 보면, my-hello-new-output로부터의 변경과 my-hello-desc로부터의 변경이 양쪽 모두 포함되어 있는 것을 발견할 수 있습니다.

다른 사람들이 작성한 변경과 더불어 일 할 때는, 최종적으로 대부분의 시간을 이런 식의 병합에 할애하게 됩니다. hg merge의 출력 마지막 줄에서 제시했듯이 저장소에 반영하는 것을 잊지 마세요.

$ hg commit -m "Merged changes from my-hello-new-output"

이 명령은 출력이 없습니다.

다음으로, KoreanTutorialConflict에서 경합하는 변경이 작성된 경우의 대처법을 배워봅시다.


CategoryKorean

KoreanTutorialMerge (last edited 2009-05-19 19:31:02 by localhost)