Skip to content

Instantly share code, notes, and snippets.

@gigq
Created March 25, 2023 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gigq/2f72a1f5a580f58069c0758c1778b960 to your computer and use it in GitHub Desktop.
Save gigq/2f72a1f5a580f58069c0758c1778b960 to your computer and use it in GitHub Desktop.
Quick bash script using gpt-ai (https://github.com/lmatosevic/chatgpt-cli) to read git diff and create a commit message
#!/bin/bash
git add .
# Run git diff and capture the output, excluding yarn.lock for js/ts projects
diff_output=$(git diff HEAD -- . ':(exclude)yarn.lock')
# Prepend the commit message to the diff output
commit_message="Output just a properly formatted git commit message from the following, be accurate and concise, no need to specify prefixes, don't assume why changes were made:"
full_output="$commit_message\n\n$diff_output"
chatgpt_message=$(gpt-ai "$full_output")
# Send the commit message to git
git commit -a -m "$chatgpt_message" -e
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment