KO EN

[Git] To modify a specific commit

by 민갤

ETC /

Precautions before working

Since forced push needs to be executed, if there is a collaborator, it will proceed after consultation to prevent the Git from being twisted.

Confirm Commit to Modify

Copy the commit hash just before it to modify feat: two.

git log
mintty.2023-09-12_10-44-53.png

git log

Enable you to modify commit

Execute the git rebase command interactively.

git rebase -i {commit_hash or HEAD}
git rebase --interactive {commit_hash or HEAD}
git rebase --interactive 8a7b752c75de3b60c4e316de10dec5b567a0b0f5

All commits in the current (HEAD) range are displayed after the specified commit hash.

mintty.2023-09-12_10-47-34.png

Change the pick displayed in front of the commit to be modified to edit and save it.

mintty.2023-09-12_10-47-48.png

When the save is complete, a notice will be displayed. Commands that correct the commit are executed after the following order.

mintty.2023-09-12_10-48-17.png

Modify Commit

Proceed with file modification.

When the modification is completed, add it to the Git preparation (staging) area with git add and commit it.

git commit --amed

The commit content displayed on the screen exits as :q.

mintty.2023-09-12_10-50-51.png

mintty.2023-09-12_10-51-11.png

Complete the git rebase.

git rebase --continue
mintty.2023-09-12_10-52-19.png

Change confirmation

You can see that the commit hash has changed from the commit modified with git log to the latest commit. You can check how many changes have been made in the git status.

mintty.2023-09-12_10-52-26.png

Apply

Overwrite the remote branch with a forced push.

git push origin dev --force
mintty.2023-09-12_10-54-08.png

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

Author

민갤

민갤

Back-End Developer

꾸잉꾸잉하고 웁니다.

로그인

디코에 오신 것을 환영해요!
전문가들의 수많은 아티클 창고 🤓