Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Astro Coke

[Git] Merge Conflicts 본문

Computer Setup

[Git] Merge Conflicts

astrodoo 2019. 7. 17. 08:24

source: https://stackoverflow.com/questions/161813/how-to-resolve-merge-conflicts-in-git

 

 


> git pull origin master

From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Updating a030c3a..ee25213
error: Entry 'filename.c' not uptodate. Cannot merge.

pull 하는 과정에서 conflict  이 발생했을 때,

아래와 같이 local 에서 add 와 commit 을 실행한 후 다시 pull 을 하면 CONFLICT 가 발생되고,

해당 파일안에는 <<<<< HEAD 와 ======= prod 와 같은 충돌지점 설명이 기록된다. 


> git add .
> git commit -m "made some wild and crazy changes"
> git pull origin master

From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Auto-merging filename.c
CONFLICT (content): Merge conflict in filename.c
Automatic merge failed; fix conflicts and then commit the result.

이때, mergetool로 충돌지점을 확인하고 수정할 수 있다.

> git mergetool
LOCAL BASE REMOTE
MERGED

Local: file from the current branch

Base: common ancestor, how file looked before both changes

Remote: file you are merging into your branch

Merged: merge result, this is what gets saved in the repo


> git pull origin master

From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Already up-to-date.

git mergetool 이후에는 filename.orig 파일이 생성되는데,

conflict를 해결한 후에는 이를 지워주어야 한다. 그냥 rm 으로 지워도 되고,

> git clean -f

로 지울수도 있다.

 

git mergetool은 다양한 프로그램을 이용할 수 있는데 

이 중 기본적으로 선택할 수 있는 것은 vimdiff 이다

 

> git config merge.tool vimdiff