ABOUT ME

Today
Yesterday
Total
  • git branch merge하기
    카테고리 없음 2023. 2. 19. 13:40

    calcuatlor.py 
    yunaaa branch에서 

    # 기본계산기
    def add(a,b):
    return a + b 

    def subtract(a,b):
    return a - b 

    def multiply(a,b):
    return a * b

    def divide_premium(a,b):
    return a/b 

    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
    $ start .

    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
    $ git add .

    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
    $ git commit -m 'change divide function as premium'
    [yunaaa c3b73a6] change divide function as premium
     1 file changed, 1 insertion(+), 4 deletions(-)

    ==============================


    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
    $ git checkout master
    Switched to branch 'master'
    Your branch is ahead of 'origin/master' by 1 commit.
      (use "git push" to publish your local commits)

    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
    $ dir
    License  README.md  calculator.py  meeting-log

    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
    $ start .

    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
    $
    # 기본계산기
    def add(a,b):
    return a + b 

    def subtract(a,b):
    return a - b 

    def multiply(a,b):
    return a * b

    def divide_free(a,b):
    return a/b 


    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
    $ git add .

    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
    $ git commit -m "change divide function as free"
    [master 645d097] change divide function as free
     1 file changed, 1 insertion(+), 4 deletions(-)

    ======================================
    위이 결과는 master, yunaaa라는 branch에서 
    divide 함수 이름을 다르게 작성하여 커밋함 

    이떄 yunaaa branch에서 master branch를 merge하려고 하면은?!

    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
    $ git merge master
    Auto-merging calculator.py
    CONFLICT (content): Merge conflict in calculator.py
    Automatic merge failed; fix conflicts and then commit the result.

    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa|MERGING)

    충돌이났따!!
    calculator.py 를 보자 

    # 기본계산기
    def add(a,b):
    return a + b 

    def subtract(a,b):
    return a - b 

    def multiply(a,b):
    return a * b

    <<<<<<< HEAD
    def divide_premium(a,b):
    =======
    def divide_free(a,b):
    >>>>>>> master
    return a/b 

    ===============

    해결하기 

    두가지 방법이 있다 

    • conflict가 발생한 부분을 직접 수정해서 해결하고 커밋을 해서 머지를 마무리하는 방법과
    • 일단 머지 작업을 취소하고 원래 상태로 돌아오는 방법


    1. devide_new(a,b) 라고 다시 정의하고 커밋하기 

    # 기본계산기
    def add(a,b):
    return a + b 

    def subtract(a,b):
    return a - b 

    def multiply(a,b):
    return a * b

    def devide_new(a,b):
    return a/b


    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa|MERGING)
    $ git add .

    yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa|MERGING)
    $ git commit
    [yunaaa 614f594] Merge branch 'master' into yunaaa

    2. merge 자체를 취소하기 

    git merge --abort

     

    ----------------------------------------------------------------------------------------------------------------------

     

    만약 한 파일이 아니라, 여러 파일에서 conflict가 난다면은?

    - 하나의 파일을 해결한 것 과 똑같은 절차로 해결한다

    • 파일 하나씩 conflict를 해결하고 git add [파일 이름] 커맨드로 하나씩 staging area에 올리거나(중간중간에 git status 커맨드로 현재 상태 확인하면서)
    • 모든 파일들의 conflict를 다 해결하고, git add . 커맨드로 한번에 staging area에 올리고

    -------------------------------------------------------------------------------- 

     

    // 브랜치 퀴즈 

    현재 base라는 브랜치에 있는 상태에서 extra라는 브랜치를 합병(merge)하려고 합니다. 
    빈 칸에 들어갈 알맞은 말
    - git merge extra

     

     

    // 

    댓글

Designed by Tistory.