Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git 사용 방법
  6. Git에서 브랜치를 사용하는 방법
  7. 병합 충돌 해결
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

병합 충돌 해결

다음으로마지막 단계에서 만든 issue2issue3 브랜치를 메인 브랜치로 병합하겠습니다.

먼저 main으로 전환하고 fast-forward 병합을 사용하여 issue2를 병합합니다.

$ git checkout main
Switched to branch 'main'
$ git merge issue2
Updating b2b23c4..8f7aa27
Fast-forward
myfile.txt |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)

이것이 이제 기록입니다.

Current history

다음으로 issue3main으로 병합해 봅니다.

$ git merge issue3
Auto-merging myfile.txt
CONFLICT (content): Merge conflict in myfile.txt
Automatic merge failed; fix conflicts and then commit the result.

이 경우 Git은 myfile.txt 파일이 각 브랜치의 동일한 라인에 다른 내용을 가지고 있고 issue3main과 자동으로 병합할 수 없기 때문에 충돌을 식별했습니다.

myfile.txt 파일은 이제 다음과 같이 표시됩니다.

Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
<<<<<<< HEAD
commit: Save the status of an index
=======
pull: Obtain the content of a remote repository
>>>>>>> issue3

충돌에 관한 정보와 함께 Git에 의해 myfile.txt 파일에 추가된 마커를 찾을 수 있습니다. 아래와 같이 충돌을 수동으로 해결해야 합니다.

Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
commit: Save the status of an index
pull: Obtain the content of a remote repository

충돌이 해결되면 변경 사항을 커밋합니다.

$ git add myfile.txt
$ git commit -m "merge issue3 branch"
# On branch main
nothing to commit (working directory clean)

그리고 기록은 다음과 같이 표시될 것입니다.

Current history

충돌 해결의 결과로 새로운 병합 커밋이 생성된 것을 볼 수 있습니다. 그리고 메인 브랜치는 이제 최신 병합 커밋을 가리키고 있습니다. 이것은 non-fast-forward 병합입니다.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life