-
Notifications
You must be signed in to change notification settings - Fork 0
Git Hook ‐ Prepare commit msg
maple edited this page Dec 23, 2024
·
2 revisions
A Git commit-msg hook that automatically adds semantic emojis to your commit messages based on conventional commit types.
- Automatically prepends appropriate emojis to your commits
- Supports conventional commit types
- Handles optional scopes in commit messages
- Preserves existing emoji commits
- Follows gitmoji standards
- Save the script as
.git/hooks/commit-msg:
curl -o .git/hooks/commit-msg https://raw.githubusercontent.com/maplepy/dotfiles/master/dot_git-templates/hooks/executable_prepare-commit-msg
chmod +x .git/hooks/commit-msg- Make it executable:
chmod +x .git/hooks/commit-msgSimply write your commits following the conventional commit format:
# Basic commit
git commit -m "feat: add new feature"
# ➡️ "✨ feat: add new feature"
# Commit with scope
git commit -m "fix(auth): resolve login issue"
# ➡️ "🐛 fix(auth): resolve login issue"| Type | Emoji | Purpose | Examples |
|---|---|---|---|
| init | 🎉 | Project initialization |
init: bootstrap projectinit(v2): start major versioninit(monorepo): setup workspace
|
| feat | ✨ | New features |
feat: add user authenticationfeat(dashboard): add data visualizationfeat(api): implement endpoints
|
| fix | 🐛 | Bug fixes |
fix: resolve memory leakfix(auth): fix token expirationfix(ui): correct alignment
|
| docs | 📝 📚 | Documentation |
docs: update API docsdocs(readme): add deployment guidedocs(api): update specs
|
| style | 🎨 | Code style/formatting |
style: apply prettier formattingstyle(css): standardize colorsstyle(lint): fix warnings
|
| Type | Emoji | Purpose | Examples |
|---|---|---|---|
| refactor | ♻️ | Code restructuring |
refactor: convert to TypeScriptrefactor(auth): switch to JWTrefactor(api): improve structure
|
| perf | ⚡️ | Performance improvements |
perf: optimize loadingperf(queries): add indexesperf(api): implement caching
|
| test | ✅ 🧪 | Testing changes |
test: add unit teststest(api): add integration teststest(e2e): add flow tests
|
| Type | Emoji | Purpose | Examples |
|---|---|---|---|
| build | 👷 | Build system |
build: upgrade webpackbuild(deps): update packagesbuild(docker): optimize image
|
| ci | 💚 | CI/CD changes |
ci: add deploymentci(github): setup actionsci(tests): add coverage
|
| chore | 🔧 | Maintenance tasks |
chore: update dependencieschore(git): update ignorechore(deps): bump versions
|
| Type | Emoji | Purpose | Examples |
|---|---|---|---|
| deps | 📦 | Dependencies |
deps: upgrade reactdeps(security): patch packagesdeps(types): update definitions
|
| security | 🔒 | Security updates |
security: add XSS protectionsecurity(auth): add rate limitingsecurity(api): add validation
|
| revert | ⏪️ | Revert changes |
revert: remove featurerevert(auth): restore sessionsrevert(ui): restore design
|
| wip | 🚧 | Work in progress |
wip: start oauthwip(ui): draft layoutwip(api): begin migration
|
| deploy | 🚀 | Deployment |
deploy: release v1.0deploy(staging): update envdeploy(prod): migrate db
|
Scopes provide additional context in parentheses:
feat(ui): add new button component
fix(auth): resolve token refresh
perf(api): optimize database queries
docs(readme): update installation stepsCommon scope categories:
- Components:
(ui),(api),(db) - Features:
(auth),(user),(admin) - Technical:
(core),(deps),(test) - Platform:
(ios),(android),(web)
- If a commit already has an emoji, it's left unchanged
- Commits without a valid prefix default to "feat"
- Scopes are optional but preserved if present
- The hook maintains the original message case
- Keep commit messages concise and descriptive
- Use scopes to indicate affected components
- Follow the conventional commits specification
- One change per commit for better history
To add or modify emoji mappings, edit the prefix_emoji array in the script:
declare -A prefix_emoji=(
["your-type"]="🔥" # Add custom types
)Feel free to submit issues and enhancement requests!
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request