Modify a Specific Commit

Modify a Specific Commit

Part of Git By Example Series

Introduction

Sometimes it is needed to change a specific commit without having the need to create a new commit for that. For this it will be used git rebase, because it allows to keep a clean git history as intended.

How to

To modify commit xxcsea45 run:

git rebase --interactive xxcsea45~

Must use the ~ because it is needed to reaply commits on top of our commit xxcsea45. In the editor look for the entry with our commit and change pick to edit. Save the file and exit. At this point xxcsea45 is your head. Make the necessary changes and then commit with the command:

git commit --all --amend --no-edit

To finish you must return to the previous HEAD:

git rebase --continue

As this procedure changes the SHA-1 of changed commit and of all commits that come after it, it is needed to force our changes to the repo:

git push --force