상세 컨텐츠

본문 제목

merge, rebase, squash merge

Git

by H_Develop 2023. 6. 23. 14:28

본문

$ git branch my-branch
$ git checkout my-branch


작업을 다 끝내고 master 브랜치에 merge를 하려고 했는데, 

내가 merge하기 전에 누군가가 master 브랜치에 다른 작업을 한 후 commit하고 push했다.

 

merge
하나의 브랜치와 다른 브랜치의 변경 이력 전체를 합치는 방법이다.
commit a, b, c를 refer하는 m이 생성되고 m을 통해 a + b + c가 master에 추가된다. (a, b, c, m 모두 커밋 객체)
m은 2개의 parent를 가진다.

$ git checkout master
$ git merge my-branch

 

squash merge
commit a + b + c를 합쳐서 새로운 commit, abc를 만들어지고 master에 추가된다.
abc는 1개의 parent를 가진다.
feature 브랜치의 commit history를 합쳐서 깔끔하게 만들기 위해 사용한다. (a, b, c 객체는 사라지고 기존 객체에 이어져 abc객체에 master가 추가된다.)

$ git checkout master
$ git merge --squash my-branch
$ git commit -m "your-commit-message"


rebase
모든 commit들이 합쳐지지 않고 각각 master 브랜치에 추가된다. 각 commit은 모두 하나의 parent를 가진다. (갈려졌던 a, b, c객체들이 하나로 이어져 c에 master가 추가된다)

$ git checkout my-branch
$ git rebase master
$ git checkout master
$ git merge my-branch

'Git' 카테고리의 다른 글

git push 에러  (0) 2023.06.25
PR(Pull request), fork - push 권한이 없는 오픈소스프로젝트에 기여  (0) 2023.06.23
linear git history, cherry-pick  (0) 2023.06.23
Branch 종류 5가지  (0) 2023.06.23

관련글 더보기