A typo in the message, or a file you forgot to add? Fix the last commit instead of adding another one:
git log --oneline
b710952 (HEAD -> main) Add teh FAQ
a44a6a0 Start the shop
git commit --amend -m "Add the FAQ"
[main 226d453] Add the FAQ ← a new hash
Date: Fri Mar 7 15:28:00 2025 +0000
1 file changed, 1 insertion(+)
create mode 100644 faq.htmlAmend replaces the last commit with a new one, so the hash changes. The old commit fades to a ghost on the graph.
Forgot a file? Stage it, and amend without changing the message:
git add faq.css
git commit --amend --no-edit
[main bed47fd] Add the FAQ
Date: Fri Mar 7 15:28:00 2025 +0000
2 files changed, 2 insertions(+)
create mode 100644 faq.css
create mode 100644 faq.htmlLeave out -m and git opens the message in the editor panel, and waits:
git commit --amend
hint: Waiting for your editor to close the file...Add the FAQ
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
# Changes to be committed:
# new file: faq.css
# new file: faq.html
#Edit the first line and save. Lines starting with # are git's notes and aren't kept; an empty message cancels. A plain git commit without -m opens the same editor for a new commit.
Only amend a commit nobody else has. Once you've shared it, fix mistakes with a new commit instead.
Objectives
- Fix the typo in the last commit's message.
- Add the forgotten
checkout.cssto that same commit.