
[Git] 특정 커밋 수정하기
ETC작업 전 주의사항
강제 푸시를 실행해야 하기 때문에 공동 작업자가 있을 경우 Git이 꼬이지 않도록 협의 후 진행한다.
수정할 커밋 확인
feat: two를 수정하기 위해 그 직전 커밋 해시를 복사한다.
shell
git log

git log
커밋을 수정할 수 있도록 설정
git rebase 명령어를 대화형으로 실행한다.
text
git rebase -i {commit_hash or HEAD}
git rebase --interactive {commit_hash or HEAD}
shell
git rebase --interactive 8a7b752c75de3b60c4e316de10dec5b567a0b0f5
지정한 커밋 해시 다음부터 현재(HEAD) 범위에 있는 모든 커밋이 표시된다.

수정할 커밋 앞에 표시되어 있는 pick을 edit으로 변경하고 저장한다.

저장이 완료되면 안내 문구가 표시된다. 커밋을 수정 처리하는 명령어들로 다음 순서 후 실행한다.

커밋 수정
파일 수정을 진행한다.
수정이 완료되면 git add로 Git 준비(staging) 영역에 추가한 후 커밋한다.
shell
git commit --amed
화면에 표시되는 커밋 내용은 :q로 빠져나온다.


git rebase를 완료한다.
shell
git rebase --continue

변경 확인
git log로 수정한 커밋부터 최신 커밋까지 커밋 해시가 바뀐 것을 확인할 수 있다. git status에서는 몇 개가 변경되었는지 확인할 수 있다.

적용
강제 푸시로 원격 브런치를 덮어쓴다.
shell
git push origin dev --force

Reference
https://docs.github.com/ko/get-started/using-git/using-git-rebase-on-the-command-line
https://homoefficio.github.io/2017/04/16/Git-과거의-특정-커밋-수정하기
https://ios-development.tistory.com/1355