티스토리 뷰

반응형

3 way merge

here base(master) there 3 way merge
A A A A
H B B H
C C T T
H D T ? conflict

 

실습: 위의 표와 같은 내용

master - base
branch - here
branch - there

base는 here과 there의 조상이 된다.
here과 there 브랜치를 생성하고 work.txt 파일을 위와 동일하게 수정하였다.

 

here에서 there를 merge 하기 전의 branch 상태

 

here에서 there을 merge 하면 conflict가 발생한다.

 

work.txt 파일을 살펴보면 마지막 H와 T가 conflict 되었다.

여기서 외부 도구를 이용한 병합 방법에 대해서 알아보겠다.
외부 도구는 여러 가지가 있지만, 
"p4 merge"라는 tool을 이용해보자.

p4merge download: https://www.perforce.com/downloads/perforce/r21.1/bin.ntx64/p4vinst64.exe

p4merge site: https://www.deviantdev.com/journal/setup-p4merge-as-mergediff-tool

 

Setup p4merge as merge/diff tool

Download and install p4merge My recommend way doing this is to use chocolatey installing p4merge like this: choco install p4merge -y Alternativly you...

www.deviantdev.com

p4merge 사용을 위한 설정 명령어:
$ git config --global merge.tool p4 merge
$ git config --global mergetool.p4 merge.path 'C:\Program Files\Perforce\p4 merge.exe'

 

.gitconfig: 이 파일 내에는 git의 환경변수들이 설정된다.
merge, mergetool 이 설정된 것을 볼 수 있다.

 

git mergetool: 외부 도구를 이용한 merge, 현재 mergetool의 default값은 p4 merge
git을 mergetool을 이용해 merge 한다.
외부 도구인 p4 merge가 종료되면 자동으로 add명령이 실행된다.

 

GUI 환경에서 DTH가 conflict 된 것을 보여준다.

 

conflict 부분을 D, T, H로 수정 후 프로그램을 종료

 

work.txt.orig: work.txt의 원본 파일
work.txt.orig파일이 생성되었다. 수정된 work.txt 파일의 내용을 확인 후 삭제하면 된다.

 

work.txt 파일이 정상적으로 수정된 것을 확인한다.

 

git을 commit 하고 branch를 확인, 정상적으로 merge 되고 branch가 생성되었다.

외부 도구를 이용하면 보다 편리하게 conflict부분을 찾아내고 수정할 수 있다.

 

출처:  https://opentutorials.org/course/3840/23687

반응형
댓글
공지사항