Git Commit Message
The gcm
script provides a guided flow to create commits with generated messages.
It starts by generating a commit message based on the staged changes in your Git repository
using an inline prompt
and then asks the user to commit the changes or to regenerate the message.
Configuration
First off, we define the script
function, which sets up our GenAI script by providing a title and a description, and specifying the model we’ll be using:
Look for changes
Next up, we check for any staged changes in your Git repository using git diff
.
If there’s nothing staged, GenAI kindly offers to stage all changes for you:
We then log the diff to the console so you can review what changes are about to be committed:
Generate and refine commit message
Here comes the interesting part. We enter a loop where GenAI will generate a commit message for you based on the diff. If you’re not satisfied with the message, you can choose to edit it, accept it, or regenerate it:
Commit and push
If you choose to commit, GenAI runs the git commit
command with your message, and if you’re feeling super confident, it can even push the changes to your repository right after:
Running the Script with GenAIScript CLI
Use the cli to run the script:
Full source (GitHub)
Content Safety
The following measures are taken to ensure the safety of the generated content.
- This script includes system prompts to prevent prompt injection and harmful content generation.
- The commit message is reviewed and approved by the user before committing the changes.
Additional measures to further enhance safety would be to run a model with a safety filter or validate the message with a content safety service.
Refer to the Transparency Note for more information on content safety.