Last Updated: February 25, 2016
·
436
· antonio83franco

Amend last git commit

Fix your last commit:

git commit --amend

Modify commit message if needed and push it to the repo:

git push origin mybranch

If you already pushed the commit you might need to force the push:

git push origin mybranch -f

1 Response
Add your response

I'm sure you know this, but it's worth noting for those reading that don't. You will need to git add your changes before you git commit --amend (like you usually do.)

Also, if you've already pushed the commit, force pushing to a remote repository can be very dangerous and I only recommend it if you absolutely know that no one has fetched those changes (like in the instance that you're working on a branch that no one else is working on.) Force pushing just needs to be done with a little caution, because it can cause major problems for other people who have based their work off of what would then be an invalid history.

over 1 year ago ·