Ad

Git: Can I Commit And Start With The Same Message As The Last Commit (NOT Amend)

- 1 answer

Jira issues are often assigned Issue numbers and titles which have to be included in the commit message - and these strings have to be the same for every commit message in a branch, across multiple commits.

Sometimes these strings are quite lengthy to type out, or inconvenient to copy and paste from Jira's webui.

For convenience I would like to use the same commit message rather than write out the same Jira issue number and title over and over again.

As an alternative can I set a default commit message for this branch? (I would like to be able to setup a default message and then edit it.)

I am not intending to copy paste the exact same message, only use the last message as a template.

Those familiar with Jira will know that the tag line or final line of the commit often always has to conform to some predefined syntax which is always the same for every commit on a branch.

Ad

Answer

git commit --reuse-message HEAD

will reuse the previous commit message.

If you want to be able to edit that message before committing, do

git commit --reuse-message HEAD --edit

The -e/--edit switch will bring up the editor.

Ad
source: stackoverflow.com
Ad