One habit quietly polluted my Git history for months. Sometimes when we make a commit and realize that a feature has been left uncommitted, we just create a new commit with a commit message close to “Project feature update final final v2”.
There is actually nothing wrong with it except the fact that it really builds up the commit history with utter nonsense commit messages. This, feeds ambiguity and ambiguity kills systems.
However, this can be fixed by a simple command.
git commit --amend
The --amend flag replaces the previous commit with a new version of that commit. To you it looks like the old commit was edited, but Git actually rewrites that part of history.
It can be thought of as replacing the previous commit with a new one; all the changes from the previous commit persist while the new changes also appear in the HEAD node, without clogging up the commit history.
- Edit the last commit message
git commit --amend
Opens your default editor to modify the message.
Or you can do it directly without opening an editor:
git commit --amend -m "Commit Message"
- Change Author or Commit Date
git commit --amend --author="Jane Doe <janedoe@gmail.com>"
git commit --amend --date="2026-06-10T12:00:00"
- Amend a commit without changing the commit message
git add forgotten-file.js
git commit --amend --no-edit
If the commit has not been pushed yet, the above commands are usually all you need. But if the commit was pushed, two cases emerge:
-
You are working alone or on a private branch
In this case, you can just push the amended commit using
git push --force-with-lease origin <branch-name>This safely overwrites the remote branch only if no one else has pushed changes since your last fetch.
Always use
--force-with-leaseinstead of--forceto prevent accidentally deleting a teammate’s work if they pushed while you were amending. -
You are working on a shared branch with your teammates
If the commit has already been pushed to a shared branch, avoid amending it unless everyone collaborating on the branch understands that history is being rewritten. In most team environments, creating a follow-up commit is usually safer than force-pushing rewritten history.
Top comments (0)