Created
December 7, 2024 12:27
-
-
Save RafalWilinski/f0167ae404c7623ffb54c1429394323a to your computer and use it in GitHub Desktop.
Generating commit messages using `llm` CLI in command line
This file contains 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