Generates conventional commit messages using AI and applies them via Graphite CLI (gt modify).
- Graphite CLI (
gt) - Cursor
agentCLI tool (AI assistant)
Add the gtma function to your shell:
source ~/.zshrc # or source the file containing gtmagtma # Generate message and amend current commit
gtma -c # Generate message and create new commit
gtma --commit # Same as -c- Detects staged/unstaged/untracked changes
- Sends diff to
agentfor conventional commit message generation - Prepends new message on top of existing commit message
- Applies via
gt modify --message
<type>(scope): <description>
<body>
<previous commit message>
# Amend with AI-generated message
gtma
# Create new commit with AI-generated message
gtma -cgtma() {
local DO_COMMIT=false
[[ "$1" == "-c" || "$1" == "--commit" ]] && DO_COMMIT=true
local CHANGES=$(git diff HEAD; git ls-files --others --exclude-standard | xargs -I {} git diff --no-index /dev/null {})
if [ -z "$CHANGES" ]; then
echo "◯ No changes detected."
return 0
fi
local OLD_MSG=$(git log -1 --format=%B 2>/dev/null)
echo "🤖 Cursor is generating commit message..."
local PROMPT="Based on the DIFF below, generate a full Git commit message.
Format:
- Header: <type>(scope): <description> (max 60 chars, imperative mood)
- Blank line
- Body: One or two paragraphs explaining the 'why' and 'what'. Wrap text at 72 chars.
Constraints:
- Types: feat, fix, docs, style, refactor, perf, test, chore.
- Output ONLY the raw commit message text. No markdown blocks, no commentary.
DIFF:
$CHANGES"
local MSG=$(agent -p "$PROMPT")
if [ -z "$MSG" ]; then
echo "❌ Generation failed."
return 1
fi
if [ -n "$OLD_MSG" ]; then
MSG="${MSG}\n\n${OLD_MSG}"
fi
echo "📝 $MSG"
if $DO_COMMIT; then
gt modify --all --commit --message "$MSG"
else
gt modify --all --message "$MSG"
fi
}
Fix the
\n\nwhen amend new message.