Change a commit message you already wrote
How do I edit a Git commit message?
Short answer
For the most recent commit, git commit --amend -m "new message" replaces it. For older commits, git rebase -i lets you mark any of them as reword. Both rewrite history, so if the commit is already pushed you'll need git push --force-with-lease and a word to your team.
git commit --amend -m "The message you actually meant"
Rewrites the most recent commit's message in place
Does this match your situation?
- You committed with a typo, the wrong ticket number, or a message like 'asdf'.
- Your team's commit convention was not followed and CI is rejecting it.
- You need to fix the message on a commit further back in history.
Step-by-step fix
Fix the most recent commit
Amend replaces the last commit with a new one carrying your new message. Nothing about the file contents changes, but the commit hash does, because the message is part of what gets hashed.
step 1git commit --amend -m "Fix: clamp player health to zero on death"Running git commit --amend with no -m opens your editor with the old message pre-filled.
Fix an older commit with interactive rebase
Start a rebase covering enough commits to include the one you want, then change its action from pick to reword. Git will stop and open an editor for each one you marked.
step 2git rebase -i HEAD~5 # In the editor, change 'pick' to 'reword' on the target line: # pick a1b2c3d Bad message → reword a1b2c3d Bad message # Save and close; Git reopens an editor for the new message.Fix several messages at once
You can mark as many lines as you like with reword in a single rebase. Git walks them in order, pausing at each so you can rewrite the message and continue.
step 3git rebase -i HEAD~10 # mark every line you want to fix as 'reword' # after each editor closes, the rebase continues automaticallyPush the rewritten history
Because the hashes changed, the remote will reject a normal push. --force-with-lease overwrites your branch but aborts if someone else pushed in the meantime, which plain --force would silently destroy.
step 4git push --force-with-leaseOnly do this on branches you own. On a shared branch, coordinate first — everyone else will need to reset to the new history.
Why this works
A commit's hash is computed from its contents, its parent, its author and its message, so changing the message necessarily produces a different commit. Git doesn't edit the old one; it creates a replacement and moves the branch pointer to it. Everything after the rewritten commit also has to be recreated, because each commit names its parent by hash — which is why rewriting a commit ten steps back rebuilds all ten. The originals stay in the reflog, so a botched rebase is recoverable.
How to stop it happening again
- Write the message in an editor rather than with -m, so you get a subject line and a body.
- Adopt a convention like Conventional Commits and enforce it with a commit-msg hook.
- Use git commit --amend freely before pushing — it's the cheapest fix there is.
Commands used in this guide
git commit --amendReplace the most recent commit instead of stacking another one on top.
git rebase -iReorder, squash, split, reword or drop your recent commits.
git pushUpload your commits to the remote repository.
git reflogThe undo history for everything - the single most important recovery command.
Still stuck?
Search the full command reference and every other rescue guide — there are 56 of them, covering everything from detached HEAD to force-push disasters.
Browse all guides →Frequently asked questions
How do I change the last commit message in Git?
Run git commit --amend -m "your new message". This replaces the most recent commit with an identical one carrying the new message. If it was already pushed, follow up with git push --force-with-lease.
How do I change an older commit message?
Use git rebase -i HEAD~n where n reaches back past the commit, then change that commit's action from pick to reword. Git pauses and opens an editor so you can write the new message, then replays the rest of the history on top.
Is it safe to amend a commit that's already pushed?
It's safe for you but disruptive for others, because the commit hash changes and anyone who pulled the old one now has divergent history. On a personal branch it's fine with --force-with-lease. On a shared branch, agree with your team first or leave the message alone.
Related rescue guides
How do I undo the last commit but keep my work?
git reset --soft HEAD~1 removes the commit and leaves every change staged, ready to recommit. Use --mixed (the default) if you also want the changes unstaged, and only use --hard if you genuinely want the work destroyed. If the commit is already pushed, revert it instead of resetting.
Read the fix →Always fixableHow do I combine multiple commits into a single commit?
git rebase -i HEAD~n opens an editor where you mark commits as squash or fixup to fold them into the one above. For a quick all-in-one collapse, git reset --soft HEAD~n followed by a fresh commit achieves the same result with no editor at all.
Read the fix →Always fixableMy commits show the wrong name or email — how do I fix them?
Set the correct identity with git config, then fix the last commit with git commit --amend --reset-author. For a range of commits use git rebase with an exec step, or git filter-repo --mailmap to rewrite the whole history at once.
Read the fix →Always fixableHow do I break a large commit into multiple commits?
Mark the commit as edit in git rebase -i, then run git reset HEAD~ to turn it back into unstaged changes. Stage the pieces one at a time with git add -p, commit each, and finish with git rebase --continue.
Read the fix →