I am trying to change a commit message in SourceTree but cannot find where the option is. It has not been pushed yet.
How can I amend the message for older commits in SourceTree or command line?
You can change the most recent commit message using the git commit --amend command. In Git, the text of the commit message is part of the commit. Changing the commit message will change the commit ID--i.e., the SHA1 checksum that names the commit.
You can use the git commit –amend command to edit a commit message. To do so, use the -m flag and specify a new commit message in quotation marks. This command will replace the single commit log message in your last commit with the one that you state.
There is no feature to do that because how git internally work, a sha1 sealing each commit.
But you could :
do a 'amend' if the message is the one of the last commit.
do a git rebase -i
also named a rebase interactive and choose 'reword' (or 'r') for each commit you want to rewrite the commit message.
use git 'notes' to join a new comment next to the existing one (but handle it is not straightforward because you have to push the note explicitely and query them also to see them... )
Suppose the branch is like A-B-C-D-E
and you want to amend C. Here is one solution I prefer:
git reset C --hard
#do some changes and add
git commit --amend
git cherry-pick C..E
#or git cherry-pick D E
git reflog
and then find its sha-id To go to that commit , use
git reset --hard sha-id
(if you don't want to keep the changes of the current state)
or,
use git reset --soft sha-id
(if you want to keep the changes)
Now do a commit --amend to the commit.....
Now, check if that the commit , you are amending to, has already been pushed or not,
if, YES, then do a rebase and push it...
`git push ` and revert back your head to where it was earlier using its sha-id
If you don't do the above step, your branch will diverge from the remote and you will see that in the git status
else, just revert back to your commit using its sha-id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With