How to edit comment of last commit

I did a commit in SourceTree (Bitbucket git repository) and then realized I forgot to add something to the comment. Is there a way to update only the comment?

1 answer

You have to use amend to change the commit message. Press the commit button and select "Amend latest commit" from the commit options on the right, above the commit message box.

If your commit was already pushed to the server, your push will be rejected afterwards. In this case you have to do a force push from the command line (git push --force) or another Git client that has this option. N.B. Your repository might be configured to reject force pushes. In this case, there is no way for you to change the commit on the server.

You really shouldn't use force push to do this on an already-pushed commit anyway, if there's any chance that other developers have pulled that commit.

Hi, I tried to use ‘Amend latest commit’ and it asks whether I want to replace comment with message from previous commit which made no sense to me in a first moment. Now I see the ‘Amend latest commit’ option remains selected (marked) which I guess means it will take effect when pressing Commit button, correct? I’ll try that on commit messages not pushed to remote repository. I think I won’t try the force push option, I’m still kind of newbie on Git and don’t want to make a mess. Thanks for your replies.

That question is only about whether you want to load and edit the previous commit message or start with a blank text. Whichever you choose, it will overwrite the commit message of the last commit with whatever you have when you press the commit button.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 23, 2018 in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

972 views 4 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you