I just want to create some standard commit messages for repositories, is this feature available? Are there any workarounds?
Asked
Active
Viewed 686 times
1 Answers
0
You can add code into your .git/hooks/prepare-commit-msg
hook that will alter message in the way you want:
#!/bin/bash
COMMIT_MSG_FILE=$1
# Only add custom message when there is no commit source
# ($COMMIT_SOURCE is empty). Otherwise, keep the default message
# proposed by Git
if [[ -z "$COMMIT_SOURCE" ]]
then
echo "Default message template goes here" > "$COMMIT_MSG_FILE"
fi

Justinas
- 41,402
- 5
- 66
- 96
-
Thanks, this is applicable only client-side, right? I'm looking for something on the Azure DevOps side – CGE Feb 16 '22 at 09:12
-
@CGE If your DevOps are making commits, then you can write script with template. – Justinas Feb 16 '22 at 13:02
-
@CGE: you cannot change a commit once it is made. Whatever person or software makes the commit chooses the commit message, which then stays the same forever. (You can make a *different* commit, as a new-and-improved replacement to be used instead, but the original commit remains unchanged.) If you're making the commit on AzDO, you'll need to set up the commit message on AzDO; if you're using `git commit` to do that, the hooks will work as usual; if not, you'll need to investigate whatever you're using to make those commits. – torek Feb 17 '22 at 00:15