Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to edit comment of last commit

Dante Hernandez May 20, 2015

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

2 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2015

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.

Tim Crall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 21, 2015

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.

Dante Hernandez May 21, 2015

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.

Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 21, 2015

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
TAGS
AUG Leaders

Atlassian Community Events