본문 바로가기
프로그래밍

git rebase 하는 방법

by 자유코딩 2021. 5. 14.

깃에 커밋을 자잘하게 너무 많이 했을때 기록을 바꾸고 싶을 수 있다.

 

최종

진짜최종

정말진짜최종

이건진짜최종커밋

..... 

 

이렇게 커밋 되었을때 맨 마지막 것 1개만 남기고 나머지 기록이 없던 것처럼 할 수 있다.

 

rebase 를 사용하면 된다.

 

git rebase -i @~2

@~2는 최근 2개 커밋들 중에서 삭제할 커밋을 고르겠다는 의미이다.

 

pick f711f6d 최종
pick 21015de 최종최종   // 여기서 pick을 s로 바꿔준다.
pick v3fer0d 정말정말최종  // 여기서 pick을 s로 바꿔준다.
# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# 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
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

 

편집 했다

pick f711f6d 최종
s 21015de 최종최종   // 여기서 pick을 s로 바꿔준다.
s v3fer0d 정말정말최종  // 여기서 pick을 s로 바꿔준다.
# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# 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
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

:wq 눌러서 저장하고 나간다

 

다음 화면으로 전환된다.

# This is a combination of 3 commits.//이 위치에서 dd를 눌러 줄을 삭제한다.
# The first commit's message is: //이 위치에서 dd를 눌러 줄을 삭제한다.
최종 //이 위치에서 dd를 눌러 줄을 삭제한다.

# This is the 2nd commit message: //이 위치에서 dd를 눌러 줄을 삭제한다.

정말최종 //이 위치에서 dd를 눌러 줄을 삭제한다.

# This is the 3rd commit message: //이 위치에서 dd를 눌러 줄을 삭제한다.

진짜정말최종 //나는 이 commit만 남기고 싶으므로 이건 냅둔다.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# rebase in progress;

 

dd 눌러서 지우고 나면 이런 모습이다.

진짜정말최종

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# rebase in progress;

:wq 해서 저장하고 나간다

이제 원격 저장소에 푸시한다

 

커밋 기록이 1개만 남고 사라진다!

'프로그래밍' 카테고리의 다른 글

블록체인 앱 개념도  (0) 2021.06.18
solidity 디앱개발 시작  (0) 2021.06.17
git merge 할때 한쪽 브랜치 내용 선택하기  (1) 2021.05.11
리액트 useMemo 사용하기  (0) 2021.05.06
개발자의 이력서 작성하기  (1) 2021.04.26

댓글