Open sorcererxw opened 1 year ago
This sounds like a perfect use case for a custom command, not really something that needs to be integrated into lazygit :)
I'm open to the idea of integrating it into lazygit if it's really good. To be clear, a good commit message has a summary of what's changing along with a description of why the change is being made and additional context you can't get from just looking at the diff. So GPT is only going to be able to help with the summary line, and the question is whether it can reliably produce a summary line that would be what the developer themselves would have come up with if they gave sufficient thought.
I'm not actually sure how reliable GPT is at doing that. Have people elsewhere used a tool that generated commit messages based on diffs and found the results were good? All I'm seeing about such tools on hacker news is derision about the idea itself, but I haven't seen much from people who actually use it (correctly) and like it.
what's going on about this issue, is it possible for integrate automate commit messages? it looks like fugitive.nvim plugin already integrated. Looking forward to the integrate of lazygit and openai haha
Recently I try the GitButler and to be honest, I addicted to the autogenerate commit messages. There are many cases that we do not need it to be fine tuned, so I would love to see this feature in lazygit too. Because, well, it's for lazy people, right?
I would love to have this feature in lazygit. After I used it in GitButler, it has raised my expectations from a git client.
Here's my custom command with aichat (https://github.com/sigoden/aichat) using modified template from https://github.com/chhoumann/bunnai/blob/af4b78efa24dce6940bb6576ad3f9f579f995111/src/template.ts
customCommands:
- key: <c-a>
description: Pick AI commit
command: |
aichat "Please suggest 10 commit messages, given the following diff:
\`\`\`diff
$(git diff --cached)
\`\`\`
**Criteria:**
1. **Format:** Each commit message must follow the conventional commits format,
which is \`<type>(<scope>): <description>\`.
2. **Relevance:** Avoid mentioning a module name unless it's directly relevant
to the change.
3. **Enumeration:** List the commit messages from 1 to 10.
4. **Clarity and Conciseness:** Each message should clearly and concisely convey
the change made.
**Commit Message Examples:**
- fix(app): add password regex pattern
- test(unit): add new test cases
- style: remove unused imports
- refactor(pages): extract common code to \`utils/wait.ts\`
**Recent Commits on Repo for Reference:**
\`\`\`
$(git log -n 10 --pretty=format:'%h %s')
\`\`\`
**Output Template**
Follow this output template and ONLY output raw commit messages without spacing,
numbers or other decorations.
fix(app): add password regex pattern
test(unit): add new test cases
style: remove unused imports
refactor(pages): extract common code to \`utils/wait.ts\`
**Instructions:**
- Take a moment to understand the changes made in the diff.
- Think about the impact of these changes on the project (e.g., bug fixes, new
features, performance improvements, code refactoring, documentation updates).
It's critical to my career you abstract the changes to a higher level and not
just describe the code changes.
- Generate commit messages that accurately describe these changes, ensuring they
are helpful to someone reading the project's history.
- Remember, a well-crafted commit message can significantly aid in the maintenance
and understanding of the project over time.
- If multiple changes are present, make sure you capture them all in each commit
message.
Keep in mind you will suggest 10 commit messages. Only 1 will be used. It's
better to push yourself (esp to synthesize to a higher level) and maybe wrong
about some of the 10 commits because only one needs to be good. I'm looking
for your best commit, not the best average commit. It's better to cover more
scenarios than include a lot of overlap.
Write your 10 commit messages below in the format shown in Output Template section above." \
| fzf --height 40% --border --ansi --preview "echo {}" --preview-window=up:wrap \
| xargs -I {} bash -c '
COMMIT_MSG_FILE=$(mktemp)
echo "{}" > "$COMMIT_MSG_FILE"
${EDITOR:-vim} "$COMMIT_MSG_FILE"
if [ -s "$COMMIT_MSG_FILE" ]; then
git commit -F "$COMMIT_MSG_FILE"
else
echo "Commit message is empty, commit aborted."
fi
rm -f "$COMMIT_MSG_FILE"'
context: files
subprocess: true
For nix users: https://github.com/deepanchal/nixos/blob/49c9e33d5ffbe5b8f2be67b4fa658acd9ccc2f20/home/features/terminal/programs/lazygit.nix#L76-L141
Usage:
Trigger with Ctrl + A
after staging files in lazygit
I am a huge fan of lazygit and use it almost every day. I am wondering if there is any plans to integrate lazygit with OpenAI/ChatGPT for automatically generating commit messages? This would be a fantastic feature that could make lazygit even lazier!
My idea for implementing this feature would be: 1.Set the OpenAI token in the lazygit config file. 2.lazygit would read the stashed files and request OpenAI to generate a commit message. 3.If the commit textarea is empty, display the generated commit message in the commit textarea with dimmed hint text. 4.Press TAB to use the generated commit message.
If there hasn’t been any progress on this front, I would be honored to offer my help.