안녕하세요,
재재입니다.

github 따라하기 다섯번째 포스팅입니다.

이번 포스팅에서는,
git stash conflict 이 발생하는 사례를 만들어 보고,
이를 해결하는 방법을 설명 드릴게요.

(1) Github 따라하기 실험 준비

먼저, conflict 환경을 만들기 위한,
임시 브랜치를 생성해볼게요.

git checkout -b 5-test-stash-err

이제, 5_resolve_conflicts 폴더에 있는 파일을 수정해보고,
변경사항을 확인해볼게요.

echo "Now, stash conflict is occurred." >> stash_err.txt
git diff

(2) remote 내용 반영

현재, 변경점이 있기 때문에
remote 내용을 반영하기 전 사용해야 할 게 있습니다.

바로, git stash 입니다.

git stash

이제, remote 내용 반영할 차례입니다.
wowoto remote 의 5-occur-stash-err branch 내용을 반영해볼게요.

git rebase wowoto/5-occur-stash-err

(3) 기존 변경점 내용 재반영

이제,
변경 된 내용을 다시 반영 할 차례입니다.

git stash pop

이제, 의도했던 conflict (충돌) 이 생겼습니다.

(4) git conflict 해결하기

위에 git stash pop 의 결과로,
아래와 같은 log 를 확인했습니다.

Auto-merging 5_resolve_conflicts/stash_err.txt
CONFLICT (content): Merge conflict in 5_resolve_conflicts/stash_err.txt
The stash entry is kept in case you need it again.

git conflict 을 해결하기에 앞서,
어떤 부분이 충돌되었는지 확인 할 차례입니다.

git diff
diff --cc 5_resolve_conflicts/stash_err.txt
index 5d641a4,c001e84..0000000
--- a/5_resolve_conflicts/stash_err.txt
+++ b/5_resolve_conflicts/stash_err.txt
@@@ -1,3 -1,3 +1,7 @@@
  This is the example with using git stash.
  This item maybe problematic for during stash pop.
- New line is added.
 -Now, stash conflict is occurred.
++<<<<<<< Updated upstream
++New line is added.
++=======
++Now, stash conflict is occurred.
++>>>>>>> Stashed changes

편한 방법은,
vscode 와 같은 tool 을 사용하는 방법도 있고,
직접 변경해서 해결하는 방법이 있습니다.

github 따라하기 image 125
Github 따라하기 – git stash conflict 3

현재는, 결국 충돌을 해결하기 위해 과거의 내용을 반영할 지,
현재의 내용을 반영할지 혹은 둘 모두를 반영할지를 결정해야 하는데요!
둘 모두를 반영하는 방법을 선택해야,
remote 의 반영내용 및 현재 변경한 내용 모두를 사용 할 수 있기 때문에,
둘 모두를 반영할게요.

This is the example with using git stash.
This item maybe problematic for during stash pop.
New line is added.
Now, stash conflict is occurred.

이제, 충돌이 모두 해결 되었습니다.

git add stash_err.txt
# if you want to set unstaged, then
# use "git reset HEAD stash_err.txt"

다음 단계 포스팅은 아래와 같습니다.

(5) 코드 url

https://github.com/wowoto9772/github-practice/tree/main/5_resolve_conflicts

Github 따라하기 – git stash conflict
태그:                 

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다