상세 컨텐츠

본문 제목

git merge 시 conflict 최대한 줄이는 방법 git merge -s recursive -X theirs mergeTarget

IT : GIT

by 인포개더러 2014. 2. 27. 01:50

본문



git merge 시 conflict 최대한 줄이는 방법 git merge -s recursive -X theirs 머지할것


merge 할때나 pull 할때 항상 문제가 되는 것이 conflict 입니다.

하지만 일반적으로 merge 를 할 때는 머지를하려는 쪽의 소스를 우선으로 머지를 해야할 경우가 많습니다. 이럴때 사용할 수 있는 merge / pull option 이 바로 MERGE STRATEGIES -s 옵션으로 사용 가능한 방법입니다.


기본 문법은 


$ git merge -s recursive -X theirs mergeTarget


라고 씁니다. mergeTarget 은 tag 나 commit id 나 branch name 등 모두 될 수 있습니다.

이렇게 하면 어떻게 동작할까요?




theirs의 반대 옵션인 ours 를 볼까요?


ours

This option forces conflicting hunks to be auto-resolved cleanly by favoring our version. Changes room the other tree that do not conflict with our side are reflected to the merge result.


This should not be confused with the ours merge strategy, which does not even look at what the other tree contains at all. It discards everything the other tree did, declaring our history contains all that happened in it.


conflict 가 나면 내가 가지고 있는 버젼으로 conflict 를 해결 한다는 것 입니다. 그러니 내 소스가 항상 우선이 되는 것이지요.


그럼 theirs 는? 머지하려고 하는 target 이 우선이 되는 것 입니다.

최종 결과를 보면 모든 소스가 target 과 동일하게 되어 있음을 알 수 있습니다.


temp branch 에 main branch 의 내용을 엎어 버리고 싶을 때 기존 temp branch의 history 는 남기고 싶다면 사용할 수 있는 방법입니다.

이상 git merge 시 conflict 최대한 줄이는 방법 git merge -s recursive -X theirs mergeTarget 에 대해 알아 보았습니다.



관련글 더보기