Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git Merge - 여러 브랜칭 시나리오 소개

Git Merge - 여러 브랜칭 시나리오 소개

유니크굿컴퍼니에서 2022년 7월 8일에 진행한 Git 세미나 진행 슬라이드입니다.

Avatar for Mu-Hun

Mu-Hun PRO

July 13, 2022
Tweet

More Decks by Mu-Hun

Other Decks in Programming

Transcript

  1. 브랜칭 시나리오 2 master 브랜치에 커밋을 몇 번 했다고 가정

    브랜칭 시나리오 — 새 이슈 체크아웃
  2. 브랜칭 시나리오 2 master 브랜치에 커밋을 몇 번 했다고 가정

    브랜칭 시나리오 — 새 이슈 체크아웃 브랜칭 시나리오 — 새 이슈 작업
  3. 브랜칭 시나리오 3 고쳐야 하는 작업이 갑자기 생기면? 아직 작업

    중인 53번 이슈와 섞이는 것을 피하기 위해 핫픽스 브랜치를 만들어서 커밋 C4
  4. 브랜칭 시나리오 : fast forward merge 4 운영 환경에 적용하려면

    hotfix 브랜치를 master 브랜치에 합쳐야 한다.
  5. 브랜칭 시나리오 : fast forward merge 4 운영 환경에 적용하려면

    hotfix 브랜치를 master 브랜치에 합쳐야 한다. $ git checkout master $ git merge hotfix Updating f42c576..3a0874c Fast-forward index.html | 2 ++ 1 file changed, 2 insertions(+)
  6. 브랜칭 시나리오 : fast forward merge 4 운영 환경에 적용하려면

    hotfix 브랜치를 master 브랜치에 합쳐야 한다. $ git checkout master $ git merge hotfix Updating f42c576..3a0874c Fast-forward index.html | 2 ++ 1 file changed, 2 insertions(+) "ಯ׼ ಯ׼ جਸ ؍૑੗ 🎶 https://t.co/giaAVuotHx" / ౟ਤఠ Pull request 2583: Updated README.md - Repos "[VSF %FWPQT ৬ (JU)VC ࢚ਵ۽ח ޷૑ਗ
  7. Merge iss53 -> master = 3 way Merge 6 п

    ࠳ے஖о оܻఃח ழ޿ ف ѐ৬ ҕా ઑ࢚ ೞաܳ ࢎਊೞৈ 3-way Mergeܳ ೤פ׮. Common ancestor Snapshot to Merge Into Snapshot to Merge In
  8. 충돌의 기초 🤯 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 ੄ ӝୡ
  9. 충돌의 기초 🤯 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 protected]</div> ======= <div id="footer"> please contact us at [email protected] </div> >>>>>>> iss53:index.html
  10. 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: 병합 할 파일을 가져온 쪽과 비교
  11. 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 를 터미널에 입력하세요!
  12. Our/Their 일괄 선택으로 자동 병합하기 10 Git — Ҋә Merge

    • 충돌이 나기 전에 두 브랜치 중 한쪽을 선택하라고 알려줄 수 있다. • merge 명령에 - Xours 나 Xtheirs 옵션을 추가하면 된다. • git merge - Xours branch name • 이래도 충돌이 날 수도 있는데 어느 한쪽을 그대로 가져오고 싶을 때 • —s ours branch name
  13. zdiff3 : Git 2.35 에 추가된 새 conflict diff 모드

    11 Git — Ҋә Merge git config ——global merge.conflictstyle zdiff3 이 모드는 충돌의 시작이나 끝에서 공통 라인을 충돌 영역 외부로 열심히 이동하여 해결해야 하는 충돌을 조금 더 작게 만듭니다.
  14. 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
  15. 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
  16. 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