-
-
Save b-barry/80367211a502665cc4e7a8b636efb394 to your computer and use it in GitHub Desktop.
Generating commit messages using `llm` CLI in command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to generate commit message using LLM | |
generate_commit() { | |
git add . | |
# Get the staged changes | |
DIFF=$(git diff --cached) | |
if [ -z "$DIFF" ]; then | |
echo "No staged changes found. Please stage your changes first using 'git add'" | |
return 1 | |
fi | |
# Generate commit message using LLM | |
COMMIT_MSG=$(echo "$DIFF" | llm "Generate a concise commit message (first line) and detailed description (separated by blank line) based on these changes. Follow conventional commits format. Git diff: ") | |
if [ -z "$COMMIT_MSG" ]; then | |
echo "Failed to generate commit message" | |
return 1 | |
fi | |
# Commit with the generated message | |
git commit -m "$COMMIT_MSG" | |
} | |
# Alias for the function | |
alias gac='generate_commit' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment