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.

충돌 해결

우리가 방금 만든 변경 사항을 푸시하려면 충돌을 수동으로 해결해야 합니다. 이를 위해 풀링을 실행하여 원격 저장소에서 가장 최근 변경 세트를 가져오겠습니다.

다음 git pull 명령을 실행합니다

$ git pull origin main
  Username:
  Password:
  remote: Counting objects: 5, done.
  remote: Compressing objects: 100% (2/2), done.
  remote: Total 3 (delta 0), reused 0 (delta 0)
  Unpacking objects: 100% (3/3), done.
  From https://example.backlog.com/git/BLGGIT/tutorial.git
  * branch            main     -> FETCH_HEAD
  Auto-merging sample.txt
  CONFLICT (content): Merge conflict in sample.txt
  Automatic merge failed; fix conflicts and then commit the result.

병합 충돌을 경고하는 메시지가 나타납니다.

sample.txt를 열면 아래와 같이 해당 파일 섹션에서 충돌을 나타내는 Git에 의해 추가된 마커가 표시됩니다.

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 the remote repository
>>>>>>> 17c860612953c0f9d88f313c8dfbf7d858e02e91

변경 사항을 모두 수락하고 마커를 제거하여 충돌을 해결할 것입니다.

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 the remote repository

충돌을 해결하고 파일 내용이 변경되면 변경 사항을 커밋합니다.

$ git add sample.txt
$ git commit -m "merge"
  [main d845b81] merge

이제 원격 저장소의 최신 변경 사항으로 업데이트되었습니다.

Git log 명령을 사용하여 저장소 기록의 정확성을 확인할 수 있습니다. --graph 옵션은 브랜치 기록을 그래프 형식으로 표시하고 --online 옵션은 출력 메시지를 압축하려고 시도합니다.

$ git log --graph --oneline
  *   d845b81 merge
  |\
  | * 4c01823 append description of the pull command
  * | 95f15c9 append description of the commit command
  |/
  * 3da09c1 append description of the add command
  * ac56e47 first commit

이는 두 기록이 새 병합 커밋과 성공적으로 병합되었음을 나타냅니다. 이제 병합 충돌 없이 이 변경 사항을 원격 저장소에 안전하게 푸시할 수 있습니다.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life