brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: fixup=reword rewrites an older commit message at your next rebase

Commit
~/tips/tip-commit-fixup-reword

git commit --fixup=reword:HEAD~1

Queue a better message for an earlier commit without touching its files.

A typo in the last message is easy to amend. For one that sits a few commits back, I like to note the correction now and apply it later.

Point at the commit whose message you want to change:

git commit --fixup=reword:HEAD~1

An editor opens. Leave the first line, which starts with amend! and repeats the old subject, and write the new message below it. Git creates a small commit that holds only that message and no file changes. When you’re ready to tidy up the branch, run:

git rebase -i --autosquash HEAD~3

The todo list already has the new commit placed under its target and marked to replace the message. Save and close, and the old commit has its new wording.

A hash works in place of HEAD~1, and you can keep working and committing between the two steps. This option needs Git 2.32 or newer.

The rebase rewrites that commit and every one after it, so their hashes change. Do it on a branch that is still yours. If others have already pulled those commits, a typo is a much smaller problem than the mess a rewritten history gives them, and I would leave it alone.

Further reading: git-commit documentation, git-rebase documentation

More Commit tips if ! head -n1 "$1" | grep -qE '^[A-Z]'; then git commit -C ORIG_HEAD git config --global commit.cleanup scissors git commit -m "Fix login redirect" -m "The old code sent signed-out users to a 404." Commit.template pre-fills your commit message All Commit tips (7) All topics

Link