vim, git, aws and other three-letter words

Software Development Notes

git: update commit message

Simple: Change Last Commit Message

To change the last commit message, use commit with the --amend flag:

Careful: commit --amend will rewrite history; do not use it on public branches.

git commit --amend

It will open an editor to change the commit message. The changes will be applied after saving the file and closing the editor.

Advanced: Change Any Commit Message or Multiple Commit Messages

Besides other things, interactive rebase allows editing commit messages:

git rebase -i HEAD~3
pick SHA-A commit message
pick SHA-B commit message
pick SHA-C commit message

Do not change commit messages just yet, only change pick in the first column to r (or the full reword):

pick SHA-A commit message
r SHA-B commit message
r SHA-C commit message

Here we schedule a commit message update for the SHA-B and SHA-C commits. After the file is saved, git will open the editor once more for each of the marked commits, where we can edit the commit message.

Alternative: Cherry-Pick Commits and Update Messages

This might be useful if we want to pick some commits from the branch and update commit messages:

# create the new branch
git checkout -b new-branch

# for every commit to pick
git cherry-pick commit-sha
git commit --amend

So we cherry-pick the needed commits and then edit commit messages with commit --amend.

Tags: git