Amend commit message in SourceTree
If you’re using Atlassian SourceTree with a git repository and you do a local commit but then realise the message was incorrect, you can amend it before you push it to remote. To set this up, you can create a “Custom Action” in SourceTree:
- Tools -> Options -> Custom Actions
- Click Add
- Set Menu caption, e.g. “Amend commit message”
- Select “Open in a separate window” and unselect “Run command silently”
- Set Script to run to “git.exe” including path
- Set Parameters to “commit –amend”
Now, whenever you want to correct the message on your latest commit, you right-click on the commit, and select “Custom Actions” -> “Amend commit message“. A terminal window will open with a vi editor open with the current commit message at the top of the file (there will also be some instructions with # at the start of each line; you can leave them alone).
If you know vi, you’ll know what to do. Here’s a quick guide:
- To start editing, press “i” and then edit the message (on the first line of the file).
- To delete everything on the line, press ESC, followed by “ddO” (this will delete the line and then return you to edit mode to type the new message)
- To save and quit, press ESC, followed by “:wq“
- To quit without making any changes, press ESC, followed by “:q!“