Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How re-push a fixed commit on Git?

I fixed some code and pushed it with an incorrect commit message. When I tried to fix the commit message, by accident I reverted the commit. The situation is now:

  • latest commit = correct commit message, but changes of previous commit undone
  • previous commit = correct commit content, but wrong commit message

All of this has already been pushed to the server.

I would like to get rid of the latest commit, change the commit message of the previous commit and push that back to the server.

I'm happy with solutions for Atlassian Source Tree but also command line is okay.

like image 968
Krumelur Avatar asked Oct 19 '25 14:10

Krumelur


1 Answers

If it's the last commit, it's easy:

git commit --amend

This brings up the editor with the last commit message and lets you edit the message. (You can use -m if you want to wipe out the old message and use a new one.)

And then when you push, do this:

git push --force <repository> <branch>

Reference: Changing git commit message after push (given that no one pulled from remote)

like image 151
rafaels88 Avatar answered Oct 22 '25 03:10

rafaels88



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!