| name | commit |
| description | Create a clean, conventional commit by inspecting changes, staging safely, and ensuring checks pass. |
| metadata | {"short-description":"Make a conventional commit"} |
Smart Git Commit
Purpose
Create a clean, conventional commit by inspecting changes, staging safely, and ensuring formatting/lint checks pass.
When to use
- You need to commit local changes and want a consistent, conventional message.
- You want to avoid accidental partial commits or unformatted code.
Workflow
- Check for changes and summarize them:
if ! git diff --cached --quiet || ! git diff --quiet; then
echo "Changes detected:"
git status --short
else
echo "No changes to commit"
exit 0
fi
git diff --cached --stat
git diff --stat
- If nothing is staged, stage only modified/deleted files (not untracked):
if git diff --cached --quiet; then
echo "No files staged. Staging modified files..."
git add -u
fi
git diff --cached --name-status
- Analyze scope/type and prepare a conventional commit message:
- Type:
feat|fix|docs|style|refactor|test|chore
- Scope: optional component/area
- Subject: concise, present tense
- Body: include rationale when needed
- Run formatting/lint checks before committing:
trunk check --ci --fix
- If this fails, stop and ask for manual fixes before committing.
- Commit with the chosen message. Do not add yourself as co-author.
Notes
- Prefer existing repo conventions if recent history shows a pattern.
- Avoid staging untracked files unless explicitly requested.