| Tested on | RHEL 10.2 (Coughlan) |
|---|---|
| Package | git 2.52.0 |
| Applies to | Any host with Git installed |
| Privilege | Normal user |
| Scope | Fix the last commit with git commit --amend: add forgotten files, keep the same message with --no-edit, update author or date, undo a bad amend, and force-push a rewritten commit. Message-only rewrites with --only, older commits, and multi-commit message fixes live in change a Git commit message. |
| Related guides | Change a Git commit message Git undo add Git reflog tutorial Git push force examples Git rebase tutorial |
You committed, then noticed the problem: a config file never made it into the snapshot, the author email is wrong, or you need to fold a tiny fix into that same commit instead of adding noise to history. git commit --amend rebuilds the latest commit on your branch — it does not patch the old object in place.
If you only need to reword the message, use git commit --amend --only and follow change a Git commit message. This page covers everything else amend is for: files, author, date, recovery, and pushed branches.
Choose the Right Amend Command
| Your situation | What to run | Notes |
|---|---|---|
| Forgot a file in the last commit | git add file then git commit --amend --no-edit |
Stages the missing path into the rebuilt commit |
| Small code fix belongs in the last commit | git add changed paths, then git commit --amend --no-edit |
Same message, updated tree |
| Change only the commit message | git commit --amend --only -m "New message" |
See change a Git commit message |
| Wrong author on the last commit | git commit --amend --author="Name <email>" --no-edit |
Updates author metadata |
| Wrong author date on the last commit | git commit --amend --no-edit --date=now |
--date sets AuthorDate; CommitDate reflects when you amend |
| Last commit already on the remote | Amend locally, then git push --force-with-lease |
Rewrites history — coordinate first |
| Regret the last amend | git reflog, then git reset --soft to the prior entry |
Reflog keeps old commits for a while |
| Need to change a commit before the last one | Not amend — use git rebase -i |
See Git rebase tutorial |
Plain git commit --amend without --only can pull in any file already staged with git add. Stage deliberately before you amend.
What Amend Actually Does
Amend replaces the tip commit on your current branch. Git builds a new commit object — new hash — even when the file tree looks identical. Your branch pointer moves forward to that replacement; the previous tip may linger in git reflog until Git expires it.
That hash change is why amending a commit someone else already pulled requires a force push, and why --force-with-lease is safer than a bare --force. Git push force examples compares both flags.
Add a Forgotten File to the Last Commit
Scenario: you committed an app change but left config.yaml untracked on disk.
Start from a repo with two commits and an untracked config file:
git log --oneline86677d1 Update app.txt
d27418e Initial commit: add app and readmeShort status shows the missing file is still untracked:
git status -sb## main
?? config.yamlThe latest commit is 86677d1, and config.yaml was never staged. Stage it, then amend without opening the editor:
git add config.yamlWith the file staged, rebuild the tip commit without opening the editor:
git commit --amend --no-edit[main c52946f] Update app.txt
Date: Fri Aug 21 08:31:55 2026 +0530
2 files changed, 2 insertions(+)
create mode 100644 config.yamlThe subject line stayed Update app.txt, but the hash changed to c52946f and Git now tracks config.yaml in that commit:
git show --stat --oneline -1c52946f Update app.txt
app.txt | 1 +
config.yaml | 1 +
2 files changed, 2 insertions(+)If you also want to reword the subject, drop --no-edit or pass -m "Update app.txt and add config.yaml". Message-only edits are covered in change a Git commit message.
Amend Without Changing the Message
Scenario: you already wrote a good subject line and only need to update the files in that commit.
Stage the paths that belong in the snapshot, then reuse the existing message:
git add app.txtWith the fix staged, reuse the existing commit message:
git commit --amend --no-editGit rebuilds the tip commit with whatever is currently staged. The message in git log stays the same; the hash and file list may not.
Use this pattern when you:
- add a file you forgot moments after committing;
- fix a one-line typo and want it in the same commit;
- adjust a config file that belongs with the change you just recorded.
If nothing is staged, amend still runs but may only refresh metadata — stage first when you mean to change files.
Change the Author on the Last Commit
Scenario: user.email was wrong when you committed, and the last commit shows the old identity.
Check what Git recorded:
git log --format='%h %an <%ae>' -1c52946f Lab User <lab@example.com>Replace the author on the rebuilt commit:
git commit --amend --author="Jane Doe <jane@example.com>" --no-edit[main 6016c4d] Update app.txt
Author: Jane Doe <jane@example.com>
Date: Fri Aug 21 08:31:55 2026 +0530
2 files changed, 2 insertions(+)
create mode 100644 config.yamlConfirm the metadata Git will show in history:
git log --format='%an <%ae>' -1Jane Doe <jane@example.com>--author sets the author name and email on the new commit. Pair it with --no-edit when the message is already correct.
Change the Author Date
Scenario: the author timestamp on the last commit is wrong and you want it to reflect the current time or a specific moment.
Inspect author and committer dates — they are separate fields and can differ:
git log --pretty=fuller -1commit 6016c4dc3a2a436b224af1c58dd4ece5d74a0e7d
Author: Jane Doe <jane@example.com>
AuthorDate: Fri Aug 21 08:31:55 2026 +0530
Commit: Lab User <lab@example.com>
CommitDate: Fri Aug 21 08:32:11 2026 +0530
Update app.txt--date changes the author date. Because amend creates a new commit, Git also records a new committer date based on when you run the amend. Update AuthorDate to now while keeping the message:
git commit --amend --no-edit --date=now[main e0559ec] Update app.txt
Author: Jane Doe <jane@example.com>
Date: Fri Aug 21 08:32:17 2026 +0530
2 files changed, 2 insertions(+)
create mode 100644 config.yamlYou can pass an explicit author timestamp instead of now:
git commit --amend --no-edit --date="2026-08-21 10:30:00 +0530"Re-run git log --pretty=fuller -1 and check that AuthorDate matches the value you passed. CommitDate reflects when the amend ran, not the string you gave to --date.
Amend a Commit You Already Pushed
Scenario: the last commit is on the remote, but it is missing a file or metadata you can still fix locally.
Work through the same local amend steps — stage, then git commit --amend --no-edit (or with --author / --date as needed). A normal push is rejected afterward because your local tip no longer matches the remote hash.
Push the replacement history only when rewriting that branch is acceptable:
git push --force-with-leaseTo gitlab.devlab.io:stackforge/deploy-kit.git
+ 86677d1...c52946f main -> main (forced update)--force-with-lease refuses to overwrite the remote if someone else pushed since your last fetch. Do not use git pull simply to clear a non-fast-forward rejection after amend — you mean to replace the remote tip, not merge unrelated histories.
Undo git commit --amend
Scenario: you amended once too often and want the previous tip commit back.
git reflog lists recent positions of HEAD, including amend operations:
git reflog -3e0559ec HEAD@{0}: commit (amend): Update app.txt
6016c4d HEAD@{1}: commit (amend): Update app.txt
c52946f HEAD@{2}: commit (amend): Update app.txtPick the entry before the amend you regret — here HEAD@{1} at 6016c4d, not a fixed offset you memorize for every repo:
git reset --soft 'HEAD@{1}'git reset --soft exits silently on success, so confirm the branch tip moved back:
git log --oneline -16016c4d Update app.txtYour branch points at the earlier commit again; staged and working-tree changes from the undone amend remain unless you used --hard. Git reflog tutorial covers harder recovery paths; Git reset examples explains --soft, --mixed, and --hard.
Amend Only Works on the Last Commit
git commit --amend always targets the newest commit on your current branch. To edit an older snapshot you need interactive rebase (edit on the target commit, amend there, then git rebase --continue) or a message-only reword flow.
For commit messages on older or multiple commits, use change a Git commit message instead of repeating amend here. For broader history surgery, see Git rebase tutorial.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Unexpected files appeared in the amended commit | Staged paths were included because --only was not used |
Reset if needed via reflog; restage only intended files; amend again with --no-edit |
fatal: You have nothing to amend |
No commits on the branch yet | Create an initial commit first — see Git init tutorial |
git push rejected after amend |
Remote still has the old hash | git push --force-with-lease when rewriting is intentional |
--force-with-lease rejected |
Remote moved since your last fetch | Fetch, inspect new remote commits, coordinate before replacing history |
| Amended the wrong commit | Amend only ever hits HEAD |
Use reflog to return, then git rebase -i for older commits |
| Lost a commit after amend | Branch no longer points at it | Search git reflog for the old hash; git reset --soft or cherry-pick it back |
| Wanted message-only change | Plain amend can change files if staged | Use git commit --amend --only — see change a Git commit message |
References
- git-commit documentation
- git-reflog documentation
- git-push documentation
- Git Tools: Rewriting History
Summary
git commit --amend rebuilds the last commit on your branch — new hash, same branch tip role. Stage forgotten or fixed files, run git commit --amend --no-edit, and the message stays while the tree updates. Use --author when identity metadata was wrong, or --date when AuthorDate was wrong, and pair --no-edit so you do not open the editor unnecessarily.
Every amend creates a replacement commit, so a pushed branch needs git push --force-with-lease after you rewrite locally. If an amend went wrong, git reflog still lists the old tip; reset to the entry before the mistake. Amend never reaches commits below the latest — older fixes belong in interactive rebase, and message-only work belongs in change a Git commit message.

