git conflict 해결

김희준·2023년 4월 12일
0

공부

목록 보기
2/2
post-thumbnail

👩‍🚀 Branch 상황

main
->helloworld.c

(branch) issue1
->helloworld.c

(branch) issue2
->helloworld.c

main->helloworld.c

#include <stdio.h>
	
int main(){

	printf("Hello");
    
    return 0;
}

issue1-> helloworld.c

#include <stdio.h>
	
int main(){

	printf("Hello");
    printf("I1\n");
    return 0;
}

issue2 -> helloworld.c

#include <stdio.h>
	
int main(){

	printf("Hello");
    printf("I2\n");
    return 0;
}

🧓 Conflict 발생

issue1 과 main 을 merge 후 issue2를 main과 merge시 Conflict 발생한다.

👷‍♀️ 해결

Git status를 사용하여 conflict가 발생한 파일을 찾아낸다.

helloworld.c에서 Conflict가 발생한걸 알 수 있다.


main의 helloworld.c 내용에서 conflict가 발생한부분을 알려준다.

#include <sdtio.h>

int main(void){

	printf("Hello");
<<<<<<<<< HEAD
	printf("I1\n");
=========
	printf("I2\n");
>>>>>>>>> issue2
	return 0;
}

helloworld.c의 코드를 충돌이 발생하지않게 수정 후 저장한다.

#include <stdio.h>
	
int main(){

	printf("Hello");
    printf("I1\n");
    printf("I2\n");
    return 0;
}

파일을 수정 후 차례대로 add . -> commit -> push 순으로 진행하면 conflict가해결된다.

🎅 느낀점

git에서 항상 문제가 발생하면 기본 1~2시간은 잡고 있어야 해결이 될까 말까였는데, 문제를 내가 발생시켜 해결 해보니 안보이던 부분의 시야가 트여서 해결의 방법으로 이어진거같다.
원래 내가 알고 있던 지식으로 해결 할 수 있는 문제 들이 있었을텐데 유독 git문제는 머리가 복잡해져서 고생을 많이 했었다.
이번 공부를 계기로 git 개념에 좀더 이해가 된거같아 많은 도움이 되었다.

profile
No passion No jun

0개의 댓글