References:
https://pinocc.tistory.com/181
https://stackoverflow.com/questions/9704296/can-git-apply-leave-conflict-markers-inline-like-git-rebase

 

Can git apply leave conflict markers inline like git rebase?

git rebase leaves the conflict markers inline in files; something like: <<<<<<< HEAD Whatever line + context is different from the previous commit ======= Whatever line + cont...

stackoverflow.com

 

패치를 적용할 때 실패하는 경우 conflict을 쉽게 보여주고 싶다.

체리픽을 하거나 git merge를 하는 경우는 다음과 같은 표시가 나와서 한눈에 보기 쉽다:

<<<<<<< HEAD
original code
=======
new code
>>>>>>> new version, new branch

 

그런데 git am, git apply, patch 를 할 때는 저런 표시(conflict markers)가 안 나와서 답답하기 그지없다.

위에 참고자료를 보고 정리한 솔루션이다.

일단 git am -3 을 한다.

git am -3 0001-foo.patch

git am 을 일단 먼저 쓰는 이유는, 기존 commit message를 그대로 활용할 수 있고, 잘 안 될 경우 --abort를 써서 쉽게 이전 상태로 원상복귀가 되기 때문이다.

컨플릭이 나서 패치에 실패하면, 그담에는 git apply -3을 한다. (--reject 옵션으로 .rej 파일이 생성되게 할 수도 있는데, 나는 알아보기 힘들더라...)

git am -3 0001-foo.patch
(실패)

git apply -3 0001-foo.patch
(실패)

(컨플릭 잡기...)

git am --continue (포기하고 원상복귀 하려면 --abort)

(반복)

 

그런데 전혀 parent가 다른 git에서 패치를 가져올 경우, git am이든 git apply든 안된다.

이도저도 안될 땐 patch --merge 쓰면 된다.

patch -p1 --merge < 0001-foo.patch
(-p1 옵션은 패치 파일의 경로 앞에 붙은 prefix를 몇 단계나 제거하고 파일경로로 받아들일지 정하는 것)

-p1 옵션은 다들 알테니 자세한 설명은 생략한다. 알아서 잘 쓰길 바랍니다.

 

+ Recent posts