11. Merge iss53
->
master
=
3 way Merge
6
각 브랜치가 가리키는 커밋 두 개와 공통 조상 하나를 사용하여 3-way Merge를 합니다.
Common
ancestor
Snapshot to
Merge Into
Snapshot to
Merge In
12. 충돌의 기초 🤯
7
$ git merge iss53
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
Git — 브랜치와 Merge 의 기초
13. 충돌의 기초 🤯
7
$ git merge iss53
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
Git — 브랜치와 Merge 의 기초
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: index.html
no changes added to commit (use "git add" and/or "git commit -a”)
vi index.html
<<<<<<< HEAD:index.html
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> iss53:index.html
14. Ours, Theirs 소개
8
Git — 고급 Merge
#! /usr/bin/env ruby
def hello
<<<<<<< ours
puts 'hola world'
=======
puts 'hello mundo'
>>>>>>> theirs
end
hello()
• ours current change
:
현재 브랜치의 작업 내역
• Theirs incoming change
:
병합 할 파일을 가져온 쪽
⚠ Rebase 에서는 ours 가 합쳐질 내역이라 정반대입니다.
병합 커밋을 하기 전에 무엇이 바뀌었는지 확인하려면 git di
ff
로 알 수 있습니다.
• git diff ——our: 병합 후의 결과를 병합 전의 내용과 비교
• git diff ——theirs: 병합 할 파일을 가져온 쪽과 비교
15. Ours, Theirs 소개 diff3 base
9
Git — 고급 Merge
git checkout --conflict=diff3 hello.rb
#! /usr/bin/env ruby
def hello
<<<<<<< ours
puts 'hola world'
||||||| base
puts 'hello world'
=======
puts 'hello mundo'
>>>>>>> theirs
end
hello()
git checkout conflict: 충돌 난 부분을 수정 중에 원래대로 되
돌리고 다시 고쳐볼려고 할때 사용
• conflict diff3
:
base 버전의 내용까지 제공한다.
• base: 공통 조상 커밋의 내용
항상 쓰고 싶다면 git config ——global merge.conflictstyle
diff3 를 터미널에 입력하세요!
16. Our/Their 일괄 선택으로 자동 병합하기
10
Git — 고급 Merge
• 충돌이 나기 전에 두 브랜치 중 한쪽을 선택하라고 알려줄 수 있다.
• merge 명령에
-
Xours 나 Xtheirs 옵션을 추가하면 된다.
• git merge
-
Xours branch name
• 이래도 충돌이 날 수도 있는데 어느 한쪽을 그대로 가져오고 싶을 때
• —s ours branch name
17. zdiff3
:
Git 2.35 에 추가된 새 conflict diff 모드
11
Git — 고급 Merge
git config ——global merge.conflictstyle zdiff3
이 모드는 충돌의 시작이나 끝에서 공통 라인을 충돌 영역 외부로
열심히 이동하여 해결해야 하는 충돌을 조금 더 작게 만듭니다.
18. TIP
:
아직 커밋하지 않은 작업을 보관하려면?
12
아직 커밋하지 않은 작업이 이동할 브랜치의 이력과 충돌한다면 브랜치 이동이 차단이 됩니다.
어딘가에 작업 내역을 보관하고 싶다면 Stash 를 사용하면 된다.
• git stash add/push: 스택에 집어넣기, git stash pop: 스택에 빼내기
• git stash apply: 스택 맨위 안빼고 가져오기
error: Your local changes to the following files would be overwritten by checkout:
file A
file B
Please commit your changes or stash them before you switch branches.
Aborting
Git - Stashing과 Cleaning
19. Git stash Clean
13
• git stash push ——keep—index: unstaging area 만 추가하기
• git stash push ——staged staging area 만 추가하기
• git stash ——patch: 대화형 수정
• git stash branch name : name 이름의 stash를 적용한 apply 브랜치를 만듬
• git clean: 추적 중이지 않은 파일을 제거
Git - Stashing과 Cleaning
20. Git stash Clean
13
• git stash push ——keep—index: unstaging area 만 추가하기
• git stash push ——staged staging area 만 추가하기
• git stash ——patch: 대화형 수정
• git stash branch name : name 이름의 stash를 적용한 apply 브랜치를 만듬
• git clean: 추적 중이지 않은 파일을 제거
Git - Stashing과 Cleaning