How do you change the last commit message in Git?
Terminal output
$ git commit –amend -m "Add first file"
[main 48a597b] Add first file
Date: Sat Jan 10 10:42:00 2026 +0000
1 file changed, 1 insertion(+)
create mode 100644 a.txt
$ git log –oneline
48a597b (HEAD -> main) Add first file
Amend creates a new commit, so the hash changes. If the commit was already pushed, you need a force push, which is risky on shared branches. See Git Commit Amend.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |