git rebase로 이전 커밋 수정하기
이미 커밋해버린 내용을 되돌리고 싶을때, git rebase를 사용할 수 있다.
참고: https://git-scm.com/docs/git-rebase
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
참고: https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---interactive