Amending Commits
Sometimes you make a commit and immediately realize you forgot to include a file or made a typo in the commit message. Instead of creating a separate commit, you can amend the previous commit.
What Is Amend?
git commit --amend lets you replace the last commit with a new one. It’s useful for small fixes without cluttering the history.Amending the Commit Message
If you only want to change the message of the last commit:
git commit --amend -m "New message"This overwrites the previous commit with a new message. The commit hash changes.Adding Forgotten Files
If you forgot to stage a file before committing, you can add it and then amend:
git add forgotten.txt
git commit --amend --no-edit--no-edit keeps the original commit message.Important: Amend Rewrites History
Amending replaces the commit with a new one. If you’ve already pushed the original commit to a remote, you’ll need to force push (
git push --force) to update it. This can disrupt collaborators, so avoid amending commits that others have based work on.Two Minute Drill
- Use
git commit --amendto modify the last commit. - Amend can change the message or add forgotten files.
- Use
--no-editto keep the existing message. - Amend rewrites history – avoid amending already‑pushed commits.
Need more clarification?
Drop us an email at career@quipoinfotech.com
