How to modify and existing commits which are still not pushed

0 votes
71 views
asked Dec 22, 2017 by Hitesh Garg (272 points)  

I have written a wrong message in a commit which is still unpushed to the remote server.
How do I change the commit message in case of latest commit and in case of multiple commits?

1 Answer

0 votes
answered Apr 30 by Hitesh Garg (272 points)  

The quickest and easiest fix I found is -

git commit --amend -m "New commit message"

Warning

  • Make sure that there are no stages changes else they will also be added to the commit.
  • These commits are not pushed to the server else you need to force push the commit

git push --force

Or

git push -f

But if this commit already exists in the working copy of others then they will face the issue as amending changes the SHA id and everyone need to resync their system.

Welcome to Codingeek Q&A, where you can ask questions and receive answers from other members of the community.
...