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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

420 views 0 1
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