git commit
templates only work with interactive message writing. Need a hook for -m
commits.
cd .git/hooks
touch commit-msg
chmod +x commit-msg
commit-msg
:
#!/bin/sh
# Get the commit message file
COMMIT_MSG_FILE=$1
# Check if the commit message already contains a "Signed-off-by" line
if ! grep -q "^Signed-off-by:" "$COMMIT_MSG_FILE"; then
# Append the "Signed-off-by" line to the commit message
echo "\nSigned-off-by: $(git config user.name) <$(git config user.email)>" >> "$COMMIT_MSG_FILE"
fi
echo "Test with commit-msg hook" > test.txt
git add test.txt
git commit -m "Test commit using -m flag"
git log --pretty=full