# How to Quickly Edit Last Commit in Git
Sometimes I forget to add files before committing. Instead of creating a new commit, I prefer to amend the last one. My quick fix looks like this:
git add . && git commit -a --amend --reset-author --no-edit
This command:
- git add . — stages all changes in the working directory.
- git commit -a --amend — updates the previous commit with these changes.
- --reset-author — resets the author info and updates the commit timestamp. Handy if you've committed with the wrong Git identity (e.g., personal email in a work repo or vice versa).
- --no-edit — keeps the original commit message unchanged.
It's a neat way to fix an incomplete commit without polluting history with unnecessary ones and deep diving into git rebase.
# Setting Up a Shortcut
If you use this often, create an alias to save time.
## Bash
echo "alias add-amend='git add . && git commit -a --amend --reset-author --no-edit'" >> ~/.bashrc
source ~/.bashrc
## Fish
alias add-amend="git add .; and git commit -a --amend --reset-author --no-edit"
Now just run add-amend whenever you need to amend your last commit.
# Bonus: Editing Old Commits with Git Rebase
If the commit you want to change isn't the last one, use git rebase -i to go back and edit it:
git rebase -i HEAD~3
In the interactive list that appears, change pick to edit (or just e) next to the commit you want to fix. Git will pause the rebase at that commit. You can then do the changes and stage them with git add. Then continue with git rebase --continue
This is great for fixing small typos or adding forgotten files without creating new commits.