Skip to content

Instantly share code, notes, and snippets.

@PedramNavid
Last active February 27, 2024 02:42
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PedramNavid/d0d3cc4c2362143b3210a9f4a2a9c566 to your computer and use it in GitHub Desktop.
Save PedramNavid/d0d3cc4c2362143b3210a9f4a2a9c566 to your computer and use it in GitHub Desktop.
LLM Git Commit
This uses llm.datasette.io and OpenAI.
I use `git commit --template` to provide the output from the LLM to Git. This way, if you do not like the results, you
can quit your editor and no commit will be made.
# Shell function for generating a diff and editing it in your default editor:
gcllm() {
GIT_DIR="$(git rev-parse --git-dir)"
TEMPLATE="$GIT_DIR/COMMIT_EDITMSG_TEMPLATE"
echo '--- DELETE THIS LINE TO SAVE ---' > "$TEMPLATE"
git diff --cached -U1 --minimal -B --compact-summary --find-copies-harder -w | head -n 1000 | llm -t gitcommit >> "$TEMPLATE"
git commit --verbose --template="$TEMPLATE"
}
# Command for creating the template
> llm templates edit gitcommit
model: gpt4
system: >
You will receive a git diff. Write a commit message as if you are a senior software engineering.
Keep the commit messages brief, but informative. Use new lines to break apart long sentences.
Type can be fix, feat, BREAKING CHANGE. Other types of commits are allowed, e.g. build:, chore:, ci:, docs:, style:, refactor:, perf:, test:, and others.
There MUST be only one type and description line.
Use this template:
<type>[optional scope]: <description>
[optional body]
Examples:
Commit message with description and breaking change footer:
feat: allow provided config object to extend other configs
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
Commit message with ! to draw attention to breaking change:
feat!: send an email to the customer when a product is shipped
Commit message with scope and ! to draw attention to breaking change:
feat(api)!: send an email to the customer when a product is shipped
Commit message with both ! and BREAKING CHANGE footer:
chore!: drop support for Node 6
BREAKING CHANGE: use JavaScript features not available in Node 6.
Commit message with no body:
docs: correct spelling of CHANGELOG
Commit message with scope:
feat(lang): add Polish language
Commit message with multi-paragraph body and multiple footers:
fix: prevent racing of requests
Introduce a request id and a reference to latest request. Dismiss
incoming responses other than from latest request.
Remove timeouts which were used to mitigate the racing issue but are
obsolete now.
prompt: >
Diff: """$input"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment