Back to articles
Stop Writing Commit Messages — Use AI Instead
How-ToTools

Stop Writing Commit Messages — Use AI Instead

via Dev.to TutorialAlex

Your git log looks like this: fix bug update stuff wip asdf more changes final fix final fix 2 Every developer has been there. Writing good commit messages takes effort you'd rather spend coding. But bad commit messages make debugging, reverting, and onboarding painful. The fix: let AI write your commit messages from your actual diff. The prepare-commit-msg Hook Git has a hook called prepare-commit-msg that runs before the commit message editor opens. We'll use it to auto-generate messages. Create .git/hooks/prepare-commit-msg : #!/bin/bash # Only run for regular commits (not merges, amends, etc.) if [ " $2 " != "" ] ; then exit 0 fi COMMIT_MSG_FILE = $1 # Get staged diff DIFF = $( git diff --cached --stat ) DIFF_CONTENT = $( git diff --cached | head -c 5000 ) if [ -z " $DIFF " ] ; then exit 0 fi # Generate commit message MESSAGE = $( curl -s https://api.anthropic.com/v1/messages \ -H "content-type: application/json" \ -H "x-api-key: $ANTHROPIC_API_KEY " \ -H "anthropic-version: 2023-0

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
2 views

Related Articles