카테고리 없음

브랜치 merge하기

yunajoe 2023. 2. 19. 13:20

# 브랜치! 

- 하나의 코드 관리 흐름 


yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git history
75494b3b9c8516938bbf65d1fdf5ee8348cef63f (HEAD -> master, tag: Version_2, origin/master) Add multiply function
23453a29860fb3bce2a87749717bfd6f1dfc0100 Add the info in README.md
74b3b85cae59f4dc2daaee15110fc7724a1812a1 readme수정
b69451e5813c4f433746acbf77a92e34a2fbb299 Update README.md
095343435235eb984761d9b19bc9c39213258237 Make REAME.md looknice
cfe4b0bcf749debcda87423ff08a0381d98d7619 add the info of calculator.py
7bcb609ce8f66cc54e82af9275a0bfe558c03de6 Create REAME.me
d5881c1e25101fa9b754a2fe7a1ded886169167f add revised texts
c30c6dc1c7cdf593952cc3cd7099b3c579c0a7b2 (tag: Version_1) Create caculator.py and License

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git branch yunaaa

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git checkout yunaaa
Switched to branch 'yunaaa'

// yunaaa라는 branch로 이동했다. 따라서 main branch와는 아무 상관이 없다. 
작업을 해서 yunaaa라는 branch에 올리면 main branch와는 아무런 상관이 없다 
yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
$ git status
On branch yunaaa
nothing to commit, working tree clean




yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
$ git status
On branch yunaaa
nothing to commit, working tree clean

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
$ ^C

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 License from free to premium"
[yunaaa 10f2f43] Change License from free to premium
 1 file changed, 1 insertion(+), 1 deletion(-)

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
$ cat License
# 기본라이센스
유료
yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ cat License
# 기본라이센스
Free
-========================================
# branch만들기, 삭제하기 


yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git branch
* master
  yunaaa

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git branch test

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git branch
* master
  test
  yunaaa

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git branch -d test
Deleted branch test (was 75494b3).

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git branch
* master
  yunaaa


# branch 만들고  바로 이동해보기 
git checkout -b [브랜치이름] 


yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git checkout -b test
Switched to a new branch 'test'

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (test)


yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (test)
$ git branch
  master
* test
  yunaaa

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

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (test)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git branch -d test
Deleted branch test (was 75494b3).

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

1. test라는 브랜치를 생성하고 그 브랜치로 바로 이동하려고 할 때

- git checkout -b test 

2.  test라는 브랜치를 삭제하려고 할 때

- git checkout -d test 

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

merge하기 

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

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

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md
        modified:   calculator.py


yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git commit -m 'ADD total function'
[master 48f81ec] ADD total function
 2 files changed, 10 insertions(+), 1 deletion(-)

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

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

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

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

def everything(a,b):
        return a+b, a-b, a*b, a/b


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




yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git branch
* master
  yunaaa

yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (master)
$ git checkout yunaaa
Switched to branch 'yunaaa'

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

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

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

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

============================================
yunaaa라는 branch에서 master branch merge 하기 



yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
$ git merge master


사진3


yunajoe@DESKTOP-ULNOHTM MINGW64 ~/Desktop/Git_Practice (yunaaa)
$ git merge master
Merge made by the 'ort' strategy.
 README.md     |  1 +
 calculator.py | 10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

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

 


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

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

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

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

def everything(a,b):
        return a+b, a-b, a*b, a/b

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

 

 

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 

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

해결하기 
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