Skip to content

Instantly share code, notes, and snippets.

@florianpasteur
Last active September 27, 2022 09:09
Show Gist options
  • Save florianpasteur/649f735ea786130922dbdd8308e547a2 to your computer and use it in GitHub Desktop.
Save florianpasteur/649f735ea786130922dbdd8308e547a2 to your computer and use it in GitHub Desktop.
Post commit hook to auto tag commits based on commit message
#!/bin/bash
# Install command:
# curl https://gist.githubusercontent.com/florianpasteur/649f735ea786130922dbdd8308e547a2/raw -o .git/hooks/post-commit && chmod +x .git/hooks/post-commit
echo "POST COMMIT HOOK"
COMMIT_HASH=HEAD
echo "commit hash: $COMMIT_HASH"
COMMIT_MESSAGE=$(git log --format=%B -n 1 "$COMMIT_HASH")
if echo "$COMMIT_MESSAGE" | grep "@tag:";
then
TAG=$(echo "$COMMIT_MESSAGE" | sed -n -e 's/.*@tag://p');
git tag -f "${TAG}" "$COMMIT_HASH"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment