merge, squash merge, rebase merge

Hyeon·2022년 7월 30일
0
post-thumbnail

branch를 병합하는 3가지 방법이 있다. 오늘은 merge, squash merge, rebase merge에 대해 정리한다.

merge commit

기본적인 merge 방법이다. merge에 대한 commit 하나가 만들어진다. commit b1, b2, b3를 참조하는 m이 생성되고 m을 통해 b1+ b2 + b3가 master에 추가된다. m은 2개의 parent를 가진다(b3,a3). 이 방법을 사용하면 merge한 branch, 마지막으로 작업한 commit, merge 시점을 쉽게 파악할 수 있다. 하지만 merge한 branch가 늘어나고 merge의 빈도가 높아지면 commit history 파악이 어려워진다.

$git checkout master
$git merge f1

squash merge

squash merge는 merge를 할 때 여러 개의 commit을 하나의 commit으로 합친 후 merge 한다. squash commit의 parent는 a3 하나이다. feature branch를 develope branch로 mrege할 때 commit history를 합쳐서 깔끔하게 만들 수 있다. feature는 어차피 삭제될 branch다.

$git checkout master
$git merge --squash f1
$git add .
$git commit -m "squash merge"

rebase merge

rebase commit은 merge 되는 branch의 commit을 base branch의 가장 뒤에 붙힌다. 이 방법을 사용하면 history가 한 줄로 깔끔해진다. 여러 개의 branch가 복잡하게 얽혀있지 않고 하나의 histroy만 읽으면 프로젝트의 이력을 이해할 수 있다. 하지만 여러 개의 commit을 rebase merge 했는데 conflict가 일어나면 merge 하려는 모든 commit에서 conflict가 일어난다. 또한 모든 commit 이력을 확인할 수 있지만, 언제 merge가 되었는지는 확인하기 어렵다.

$git checkout f1
$git rebase master
$git checkout master
$git merge f1

profile
요즘 인터렉티브한 웹에 관심이 많습니다.

1개의 댓글

comment-user-thumbnail
2022년 7월 30일

황사장님 잘지내시죠?

답글 달기