Reputation: 41438
I use git merge --no-edit ...
in a script.
When doing git merge --no-edit ...
, git generates an automatic commit message like:
It's possible to customize that message by doing git merge --no-edit -m "Custom message"
, but that overrides the automated one.
I'd like to have both: A custom message, but also keep the automated one appended to it.
Is there such a possibility? For example, via a placeholder like git merge -m "Custom message $AUTOMATIC_MESSAGE"
? (is there such a magic placeholder?)
Edit 1:
One way to achieve what I want would be
git merge
to create a merge with automated messagegit commit --amend
to edit the message in editor and preprend "Custom message"However, I want the merge to be automated without a stop in editor.
Edit 2:
I realized I could proceed as follows in a script: do a merge with an default automatic message, then read that automated merge message post-factum via git log -1 --pretty=%s
, then amend the message:
git merge ...
git commit --amend -m "Custom message: $(git log -1 --pretty=%s)"
However, is there a more efficient way by using just git merge
without amending the commit?
Upvotes: 2
Views: 99
Reputation: 41438
(Suboptimal but working self-answer)
It's possible to customize the merge message while preserving the original one by first doing a merge, then reading the automated commit message, then amending it.
git merge ...
ORIGINAL_MERGE_MESSAGE=$(git log -1 --pretty=%s)
git commit --amend -m "Custom message: ${ORIGINAL_MERGE_MESSAGE}"
(However I'd be happy to have a better solution).
Upvotes: 3