티스토리 뷰


git은 기본적으로 remote에 commit을 하고 commit되어 있는 내용을 원격서버로 push하는 개념입니다.


remote에는 자유롭게 commit을 할 수 있는데요, 하지만 이게 독이 되는 경우가 있습니다.

잦은 remote에 commit을 그대로 원격서버에 push하는 경우에 서버의 log가 지저분해질 우려가 있습니다.

(다수의 개발자가 각자 push를 할테니까요)


그래서, 이때 필요한게 remote의 commit들을 합치는 rebase입니다.

일단 개념에 앞서 아래와 같이 remote에 commit된 내용들이 있습니다.

(git://github.com/tswicegood/mysite-chp5.git 로 테스트를 진행했습니다.)

[oops@ mysite-chp5]$ git log

commit f329ec330f03e1c4faf5b9b391f817ae0a256520

Author: 홍길동 (oops) <oops@oops.co.kr>

Date:   Wed Feb 12 15:03:26 2014 +0900


    세번째 테스트


commit cf6e33b3edd13799d6db3d469866ee0b6437918e

Author: 홍길동 (oops) <oops@oops.co.kr>

Date:   Wed Feb 12 15:03:16 2014 +0900


    두번째 테스트


commit 762921260a51ba2d9d48533c1ecd4cb3fa57f8a7

Author: 홍길동 (oops) <oops@oops.co.kr>

Date:   Wed Feb 12 15:03:04 2014 +0900


    첫번째 테스트


.......


이제 테스트로 commit한 세개의 로그를 합치도록 하겠습니다.

[oops@ mysite-chp5]$ git rebase -i HEAD~3


위와 같이 명령을 입력하게 되면 편집창이 출력됩니다.

[oops@ mysite-chp5]$ git rebase -i HEAD~3


pick 7629212 첫번째 테스트

squash cf6e33b 두번째 테스트

squash f329ec3 세번째 테스트


# Rebase 0fab167..f329ec3 onto 0fab167

#

# Commands:

#  p, pick = use commit

#  r, reword = use commit, but edit the commit message

#  e, edit = use commit, but stop for amending

#  s, squash = use commit, but meld into previous commit

#  f, fixup = like "squash", but discard this commit's log message

#  x, exec = run command (the rest of the line) using shell

#

# If you remove a line here THAT COMMIT WILL BE LOST.

# However, if you remove everything, the rebase will be aborted.

#


위 세줄을 아래와 같이 변경해줍니다.

pick 7629212 첫번째 테스트

squash cf6e33b 두번째 테스트

squash f329ec3 세번째 테스트


# Rebase 0fab167..f329ec3 onto 0fab167

#

# Commands:

#  p, pick = use commit

#  r, reword = use commit, but edit the commit message

#  e, edit = use commit, but stop for amending

#  s, squash = use commit, but meld into previous commit

#  f, fixup = like "squash", but discard this commit's log message

#  x, exec = run command (the rest of the line) using shell

#

# If you remove a line here THAT COMMIT WILL BE LOST.

# However, if you remove everything, the rebase will be aborted.

#


주석(Rebase 0fab167..f329ec3 onto 0fab167)에 표현되어 있듯이 7629212 안으로 나머지 cf6e33b,f329ec3 를 합치는 개념입니다.

저장하고 빠져나오면 새로운 편집창이 출력됩니다.

# This is a combination of 3 commits.

# The first commit's message is:

첫번째 테스트


# This is the 2nd commit message:


두번째 테스트


# This is the 3rd commit message:


세번째 테스트


# Please enter the commit message for your changes. Lines starting

# with '#' will be ignored, and an empty message aborts the commit.

# Not currently on any branch.

# Changes to be committed:

#   (use "git reset HEAD <file>..." to unstage)

#

#   modified:   hello.html

#


세개의 메시지를 합쳐서 대표하는 메시지를 작성하도록 합니다.

# This is a combination of 3 commits.

세개의 테스트를 합침

# Please enter the commit message for your changes. Lines starting

# with '#' will be ignored, and an empty message aborts the commit.

# Not currently on any branch.

# Changes to be committed:

#   (use "git reset HEAD <file>..." to unstage)

#

#   modified:   hello.html

#


저장하고 빠져나오도록 합니다.

그리고 로그를 살펴보면 아래와 같이 정상적으로 rebase되었음을 확인할 수 있습니다.

[oops@ mysite-chp5]$ git log

commit 354019785cfa31860a1387f44fb1b36e4a2d5954

Author: 홍길동 (oops) <oops@oops.co.kr>

Date:   Wed Feb 12 15:03:04 2014 +0900


    세개의 테스트를 합침




이것은 rebase의 극히 일부 기능일 뿐입니다.

나머지 기능은 차차 알아가도록 합니다 ^^

댓글
최근에 올라온 글
최근에 달린 댓글
글 보관함
Total
Today
Yesterday