Skip to content

Instantly share code, notes, and snippets.

@johhansantana
Last active August 7, 2024 18:46
Show Gist options
  • Save johhansantana/6b5524552eb9402fb32c7e0a0eb61766 to your computer and use it in GitHub Desktop.
Save johhansantana/6b5524552eb9402fb32c7e0a0eb61766 to your computer and use it in GitHub Desktop.
Use this prompt to get an AI to create a commit message based on your git changes
#!/bin/bash
# Print current working directory
echo "Current working directory: $(pwd)"
# Function to run a command and capture its output, including errors
run_command() {
echo "$ $1"
output=$($1 2>&1)
echo "$output"
echo
}
# Capture the output of various Git commands
output="Git changes since last commit:\n\n"
# Check if HEAD exists
if git rev-parse --verify HEAD >/dev/null 2>&1; then
output+="$(run_command "git diff HEAD")"
else
output+="No commits yet. Showing all changes:\n"
output+="$(run_command "git diff --no-index /dev/null .")"
fi
output+="$(run_command "git status --porcelain")"
output+="$(run_command "git log -1 --pretty=format:'%h - %s (%cr) <%an>'")"
# Add a prompt for the AI
output+="\nBased on these changes, please suggest a commit message using the git commit message syntax."
# Copy the output to clipboard
echo -e "$output" | pbcopy
echo "Git changes have been copied to your clipboard. You can now paste this information to the AI to generate a commit message."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment