Published on

How to Amend or Re-edit an Earlier Commit in Git

Authors
  • avatar
    Name
    Shelton Ma
    Twitter

To re-edit the latest git commit message, run

git commit --amend

Re-edit an Earlier Commit

1. Start an Interactive Rebase(replace n with the number of commits you want to go back)

git rebase -i HEAD~n

2. Choose the commit to edit

pick abc123 First commit
pick def456 Second commit
pick ghi789 Third commit

Change the word pick to edit (or e) for the commit you want to re-edit:

pick abc123 First commit
edit def456 Second commit
pick ghi789 Third commit

3. Git will stop at the selected commit. To edit the commit message, run

git commit --amend

4. Continue the Rebase

git rebase --continue

3. If the Commit Has Been Pushed

git push --force