Git

git rebase로 이전 커밋 수정하기

쉽게가자 2020. 5. 23. 14:14

이미 커밋해버린 내용을 되돌리고 싶을때, git rebase를 사용할 수 있다.

 

참고: https://git-scm.com/docs/git-rebase

 

Git - git-rebase Documentation

In interactive mode, you can mark commits with the action "edit". However, this does not necessarily mean that git rebase expects the result of this edit to be exactly one commit. Indeed, you can undo the commit, or you can add other commits. This can be u

git-scm.com


git-rebase - Reapply commits on top of another base tip


공식 문서의 설명으로는, 지정한 베이스 위에, 이전 커밋 리스트를 하나씩 쌓아올리는 명령이라고 한다.

 

보통 -i 옵션을 주고 인터랙티브 모드로 실행시키는데, 이렇게 하면 텍스트 에디터를 이용해서 쉽게 이전 커밋을 변경할 수 있다.

git rebase -i

 

과거의 커밋의 변경사항을 수정하려면 다음과 같이 하면 된다.

 

1. 리베이스 명령을 인터랙티브 모드로 실행시킨다.

 

2. 텍스트 에디터가 열리고, 각 행에 다시 쌓아올릴 커밋들이 표시된다.

 

3. 변경하고 싶은 커밋에 해당하는 행으로 이동하여, 맨 앞의 pick을 edit 으로 바꾸고 텍스트 에디터를 닫는다.

 

4. 해당 커밋이 수행된 직후로 돌아가게 되므로, 이 상태에서 git commit --amend를 이용하여 커밋 내용을 수정하면 된다.

 

5. 수정이 모두 끝나면 git rebase --continue 를 입력하여 다음 스텝으로 넘어간다. 이때, 더 이상 변경할 커밋이 없으면 rebase가 종료된다.

 

참고: https://backlog.com/git-tutorial/kr/stepup/stepup7_6.html

 

6. rebase -i 로 커밋 수정하기 【튜토리얼 3: 커밋을 변경해보자! 】 | 누구나 쉽게 이해할 수 있는 G

6. rebase -i 로 커밋 수정하기 【튜토리얼 3: 커밋을 변경해보자! 】 | 누구나 쉽게 알 수 있는 Git에 입문하신 것을 환영합니다. Git을 사용해 버전 관리를 할 수 있도록 함께 공부해봅시다!

backlog.com

참고: https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---interactive

 

Git - git-rebase Documentation

In interactive mode, you can mark commits with the action "edit". However, this does not necessarily mean that git rebase expects the result of this edit to be exactly one commit. Indeed, you can undo the commit, or you can add other commits. This can be u

git-scm.com