Git Reword HEAD
Goal
Reword the latest commit message safely, without unintentionally altering the commit contents.
Workflow
- •
Verify there is a HEAD commit.
- •Run
git rev-parse --verify HEAD. - •If it fails, stop and report that there is no commit to amend.
- •Run
- •
Check repo state.
- •Run
git status -sb. - •If there are staged changes, warn that
git commit --amendwill include them.- •Offer to unstage with
git resetor proceed as-is.
- •Offer to unstage with
- •Run
- •
Show the current HEAD message for context.
- •Run
git log -1 --pretty=%sfor the subject line. - •Run
git log -1 --pretty=%Bfor the full message when needed.
- •Run
- •
Collect the new commit message from the user.
- •Follow the commit message format and rules from the
git-commitskill. - •Ask for the required parts (type/scope/summary, body bullets) as needed.
- •Follow the commit message format and rules from the
- •
Amend the commit message.
- •Use repeated
-mflags:- •
git commit --amend -m "<subject>" -m "<body line 1>" -m "<body line 2>"
- •
- •If the user wants to edit in an editor instead, run
git commit --amendwithout-m.
- •Use repeated
- •
If the commit was already pushed, warn before any push.
- •Explain that rewriting history requires
git push --force-with-lease. - •Do not push unless the user explicitly asks.
- •Explain that rewriting history requires
Notes
- •Keep the subject under ~72 characters when possible.
- •Avoid amending if the user is unsure about staged changes; resolve staging first.