In my local repo I have one commit with an incorrect commit message.
I\'ve already published the incorrect commit message with git push
.
Now the
If you're not pushed the code to your remote branch(Github/Bitbucket) you can change the commit message on the command line as below.
git commit --amend -m "Your new message"
If you're working on a specific branch do this.
git commit --amend -m "BRANCH-NAME: new message"
If you've already pushed the code with wrong message then you need to be careful when changing the message. i.e after you change the commit message and try pushing it again you end up with having issues. To make it smooth follow these steps. Please read the entire answer before doing it
git commit --amend -m "BRANCH-NAME : your new message"
git push -f origin BRANCH-NAME # Not a best practice. Read below why?
Important note: When you use the force push directly you might end up with code issues that other developers are working on the same branch. So to avoid that conflicts you need to pull the code from your branch before making the force push
git commit --amend -m "BRANCH-NAME : your new message"
git pull origin BRANCH-NAME
git push -f origin BRANCH-NAME
This is the best practice when changing the commit message, if it was already pushed.