George Garside Blog

A place of many ramblings about macOS and development. If you find something useful on here, it's probably an accident. • See all Git of the day at

Don't keep creating new commits to fix something small in a previous commit. New commits clutter the history and make it harder to review and audit later.

Having created a commit with git commit, the commit can be edited1 with staged changes.

Keep commit message

As one would normally do for a new commit, git add any further changes (or use -a to commit all modifications to tracked files), then

git commit --amend --no-editCode language: Shell Session (shell)

The two options on this command are

  • --amend to change the current commit (at HEAD).
  • --no-edit to not edit the commit message. This can be omitted to open your editor to modify the commit message.

The new commit created as part of the amend will have a new hash. Any commits with the old commit as ancestor won't be moved.

Change commit message

While it is common to not wish to edit the commit message when amending for small changes. To edit the commit message, omit --no-edit. Git opens the configured Git editor to allow you to edit the commit message, whether there are any staged changes or not. Save and close the file to continue amending.

  1. Commits cannot be modified, but a new commit can be created replacing the existing commit. ↩︎

Leave a Reply

No comments