I did a Git commit and push, but wrote the totally wrong thing in the comment.
How do I change the comment? I have already pushed the commit to the remote.
I did a Git commit and push, but wrote the totally wrong thing in the comment.
How do I change the comment? I have already pushed the commit to the remote.
git commit --amend
will allow you to edit the commit message.
If you already pushed that commit, you need to run git push --force
. Only do that if you are sure nobody pulled it yet!
If people pulled the commit from your repo, simply leave the message as it is.
If you wrote the wrong thing and the commit has not yet been pushed, you can do the following to change the commit message:
$ git commit --amend
This will open your default text editor, where you can edit the message. On the other hand, you can do this all in one command:
$ git commit --amend -m 'xxxxxxx'
If you have already pushed the message, you can amend the commit and force push, but this is not recommended.
To force push : git push --force
It is generally not suggested to use --force
during git push
as it has potential to reset the remote branch to your local branch changes, so the people presently working on the remote branch or sub-branch from the remote branch will be working on out of sync files, as the parent branch is hard reset.
So there is a cleaner way to handle this.
For the latest commit: In your current branch:
git commit --amend -m "New Commit"
git pull
(This will merge based on the ort strategy)git push origin <current_branch>