| name | git-commit-renamer |
|---|---|
| description | Safely rename Git commit messages, including the latest commit, older local commits, and already-pushed commits that require history rewrites. Use this skill whenever the user wants to rename, reword, edit, fix, or change a Git commit message, whether they say "last commit," "older commit," "unpushed commit," "pushed commit," "commit on remote," or ask how to do it safely without breaking history. |
Use this skill when the task is to rename one or more Git commit messages. The main goal is to choose the safest workflow for the commit's state:
- Unpushed latest commit
- Unpushed older commit
- Pushed commit on a remote branch
The critical distinction is whether the commit has been pushed. Renaming an unpushed commit is usually straightforward. Renaming a pushed commit rewrites history and can disrupt collaborators unless handled carefully.
- Determine whether the target commit has been pushed before suggesting or running rewrite commands.
- Prefer the smallest rewrite that solves the task.
- Never rewrite shared remote history casually. If the commit is already pushed, make the user-facing risk explicit.
- When rewriting a pushed branch, prefer
git push --force-with-leaseover--force. - Do not use destructive Git commands like
git reset --hardunless the user explicitly asks. - Verify the resulting history with a log command after the rename.
Inspect the branch and identify:
- Which commit needs renaming
- Whether it is the latest commit or an older one
- Whether it exists on the upstream branch
- Whether the working tree is clean enough for a rebase or amend
Useful inspection commands:
git status --short
git branch --show-current
git log --oneline --decorate -n 10
git rev-parse --abbrev-ref --symbolic-full-name @{u}
git log --oneline @{u}..HEADInterpretation:
- If the commit is only in
@{u}..HEAD, it has not been pushed to the upstream branch. - If the commit is already on the remote branch, renaming it will require history rewriting and a force-push.
If no upstream branch exists, say so clearly and treat the branch as not yet pushed unless other evidence says otherwise.
Use:
git commit --amend -m "New commit message"Then verify:
git log --oneline -n 3This is the preferred path for the common "rename my last commit" request.
Use interactive rebase with reword:
git rebase -i HEAD~NWhere N includes the target commit in the rebase range. Change the target commit from pick to reword, save, then provide the new message when Git prompts for it.
After the rebase:
git log --oneline --decorate -n 10If conflicts appear, resolve them, continue the rebase, and confirm the final history.
Use:
git commit --amend -m "New commit message"
git push --force-with-leaseOnly do this when the user wants the remote history rewritten and understands the branch impact. Make it explicit that collaborators may need to re-sync their local branch.
Use interactive rebase plus a safe force-push:
git rebase -i HEAD~N
git push --force-with-leaseThis is the highest-risk case because it rewrites published history for the target commit and every descendant commit in the rewritten range.
When the commit is already pushed, clearly say:
- The branch history will be rewritten.
- Anyone else using that branch may need to rebase or reset their local copy.
--force-with-leaseis safer than--forcebecause it refuses to overwrite unexpected remote updates.
Do not be vague about this. The user should understand that a pushed commit rename is not just a local metadata edit.
- Inspect the branch and upstream state.
- Tell the user which case applies.
- Run the minimal rename workflow.
- If a pushed branch was rewritten, push with
--force-with-lease. - Show the relevant final log output in a concise summary.
When carrying out the task, structure the result like this:
Target commit: <latest commit or specific hash>
State: <unpushed latest | unpushed older | pushed latest | pushed older>
Action taken: <amend | interactive rebase | amend + force-with-lease | rebase + force-with-lease>
Verification: <short log summary>
Risk note: <only include when pushed history was rewritten>- If the user only asks for instructions, explain the right command sequence without running it.
- If the repo is in the middle of a rebase, merge, or cherry-pick, stabilize that state before starting another history rewrite.
- If there are uncommitted changes that could interfere with the rewrite, call that out and decide whether to proceed carefully or ask the user.
- If the branch is shared and the user does not clearly want a rewrite, recommend making a follow-up commit instead of rewriting published history.
Example 1: User: "Rename my last commit to fix the wording."
Apply git commit --amend -m ... if it is not pushed yet. If it was pushed, explain that the remote branch must be force-pushed with --force-with-lease.
Example 2: User: "Change the message for the commit three back."
Use git rebase -i HEAD~3 or a larger range that includes the target commit, mark it as reword, then verify the updated history.
Example 3: User: "Rename the commit that is already on origin/main."
Treat this as a pushed-history rewrite. Make the risk explicit and use rebase or amend as appropriate, followed by git push --force-with-lease.