How to Change a Git Commit Message

When working with Git, you may need to edit a commit message to fix a typo, remove sensitive information, or add missing details.
This guide explains how to change the message of the most recent commit or older commits.
Quick Reference
| Task | Command |
|---|---|
| Amend the last commit message | git commit --amend -m "New message" |
| Amend without changing the message | git commit --amend --no-edit |
| Open editor to amend last commit | git commit --amend |
| Force push amended commit | git push --force-with-lease origin branch |
| Interactive rebase for older commits | git rebase -i HEAD~N |
For a printable quick reference, see the Git cheatsheet .
Change the Most Recent Commit Message
The git commit --amend command rewrites the most recent commit with a new message. The amended commit is a completely new Git object with a different SHA — the original commit no longer exists on the current branch.
Amend an Unpushed Commit
If the commit has not been pushed to a remote repository, amending it is safe and straightforward.
Navigate to the repository directory in your terminal.
Run the following command to rewrite the message of the latest commit:
Terminalgit commit --amend -m "New commit message."The
-moption lets you write the new message directly on the command line without opening an editor. To open your default editor instead, rungit commit --amendwithout-m.If you also want to include changes you forgot to stage, add them before amending:
Terminalgit add forgotten-file.txt git commit --amend -m "New commit message."
Amend a Pushed Commit
Amending a commit that has already been pushed rewrites history. This can cause problems for anyone who based work on the original commit. Consult your team before amending a pushed commit.
Amend the message of the latest pushed commit:
Terminalgit commit --amend -m "New commit message."Force push to update the remote repository history:
Terminalgit push --force-with-lease <remote> <branch>Use
--force-with-leaseinstead of--force. It refuses to overwrite the remote branch if someone else has pushed to it since your last fetch, protecting you from accidentally discarding their work.
Add Staged Changes Without Changing the Message
To amend the most recent commit by adding staged changes without touching the commit message, use --no-edit:
git add forgotten-file.txt
git commit --amend --no-editThis updates the commit with the new file while keeping the original message intact.
Change an Older or Multiple Commit Messages
To change the message of an older commit or several commits at once, use an interactive rebase.
Navigate to the repository containing the commit you want to change.
Start an interactive rebase for the last
Ncommits. For example, to work with the last five commits:Terminalgit rebase -i HEAD~5Git opens the last N commits in your default text editor :
plainpick 43f8707f9 fix: update dependency json5 to ^2.1.1 pick cea1fb88a fix: update dependency verdaccio to ^4.3.3 pick aa540c364 fix: update dependency webpack-dev-server to ^3.8.2 pick c5e078656 chore: update dependency flow-bin to ^0.109.0 pick 11ce0ab34 fix: Fix spelling. # Rebase 7e59e8ead..11ce0ab34 onto 7e59e8ead (5 commands)Replace
pickwithrewordon each line whose message you want to change:plainreword 43f8707f9 fix: update dependency json5 to ^2.1.1 reword cea1fb88a fix: update dependency verdaccio to ^4.3.3 pick aa540c364 fix: update dependency webpack-dev-server to ^3.8.2 pick c5e078656 chore: update dependency flow-bin to ^0.109.0 pick 11ce0ab34 fix: Fix spelling. # Rebase 7e59e8ead..11ce0ab34 onto 7e59e8ead (5 commands)Save the file and close the editor.
For each commit marked
reword, Git opens a new editor window. Edit the message, save, and close:plainfix: update dependency json5 to ^2.1.1Once all messages are updated, force push the changes to the remote repository:
Terminalgit push --force-with-lease <remote> <branch>
FAQ
Can I amend a commit without changing the message?
Yes. Use git commit --amend --no-edit after staging the changes you want to add. Git rewrites the commit with the new content but keeps the original message.
What is the difference between --force and --force-with-lease?--force overwrites the remote branch unconditionally. --force-with-lease checks that no one else has pushed to the branch since your last fetch and aborts if they have. Always prefer --force-with-lease when pushing amended or rebased commits to a shared repository.
Should I amend or revert a pushed commit?
Amending rewrites history and requires a force push, which can disrupt collaborators. If the commit is already on a shared branch, it is usually safer to revert it
— which creates a new commit that undoes the change without altering history.
How do I undo the last commit entirely?
Use git reset
to move the branch pointer back. git reset --soft HEAD~1 keeps your changes staged; git reset --hard HEAD~1 discards them entirely.
Can I change the commit author as well as the message?
Yes. Each commit records the author identity
configured at the time it was made. To update it along with the message, add --reset-author: git commit --amend --reset-author -m "New message.".
Conclusion
To change the most recent commit message, use git commit --amend. To change older or multiple commit messages, use git rebase -i HEAD~N. When force pushing amended commits to a remote, always use --force-with-lease instead of --force.
Do not amend commits that have already been pushed to a shared branch without first coordinating with your team, as it rewrites history for everyone working on that branch.
For a full Git command reference, see the Git cheatsheet .
If you have any questions, feel free to leave a comment below.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page