About Git Rebase

Rebase

 Git history 관리면에서 유용한 rebase 사용의 장점과 사용법을 설명합니다.

Why

git merge history

git merge 작업후 git history는 아래와 같은 형태가 됩니다.

여러 지점에 걸쳐 분기와 병합 작업을 수행한 모든 내역을 표시하게 됩니다.

병합시에 병합 커밋 하나가 생성됩니다.

Git Merge


 미래의 git merge history 모습

git rebase history

git rebase 작업후 git history는 아래와 같은 형태가 됩니다.

feature 브랜치에서 작업한 commit '#3 과 commit '#4 는 선형적으로 새로운 commit 이 추가된 것으로 인식합니다.

즉, 커밋 히스토리를 재 구성하여 git history 를 선형적으로 유지할 수 있습니다.

git history를 선형적으로 구성되어 관리가 매우 편합니다.

단, 커밋 히스토리가 재 구성되어도 문제없음을 확신하는 경우에 사용하는 것이 좋습니다. 

Git Rebase

Usage

git rebase 의 기능들은 아래와 같습니다.

사용하는 방법은 work flow를 확인하세요.

git rebase -help 원본 펼치기

Work flow


1. Git clone 하기




$ git clone http://git.kdiwin.com:7990/scm/micp/infra.git
Cloning into 'infra'...
remote: Enumerating objects: 330, done.
remote: Counting objects: 100% (330/330), done.
remote: Compressing objects: 100% (311/311), done.
remote: Total 330 (delta 170), reused 0 (delta 0)
Receiving objects: 100% (330/330), 1.25 MiB | 8.54 MiB/sdone.
Resolving deltas: 100% (170/170), done.
 
$ git branch
* master

2. 'feature' 브랜치 하기




$ git checkout -b feature
Switched to a new branch 'feature'
 
$ git branch
* feature
  master

3. 작업 내용 commit 하기




$ git add *
 
$ git commit -m "updates"
[feature b57ef3d] updates
 file changed, 1 insertion(+)

4. Local master 로 이동하여 git pull 하기




$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
 
$ git pull
Already up to date.

5. 'feature' branch 로 이동하여 local master 를 rebase 하기




$ git checkout feature
Switched to branch 'feature'
 
$ git rebase master
Current branch feature is up to date.

6. Local master 로 이동하여 'feature' branch를 rebase 하기



$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
 
$ git rebase feature
First, rewinding head to replay your work on top of it...
Fast-forwarded master to feature

7. git push 하기



$ git push
Counting objects: 3, done.
Delta compression using up to 6 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 276 bytes | 276.00 KiB/sdone.
Total 3 (delta 2), reused 0 (delta 0)
To http://git.kdiwin.com:7990/scm/micp/infra.git
   ba8ea29..b57ef3d  master -> master

Reference

댓글

이 블로그의 인기 게시물

CDK - Assets

About VPC

dailyFocus - Frontend