All magit-gptcommit commit[1:]
generated by magit-gptcommit.
magit-gptcommit.intro.mp4
magit-gptcommit depends on gptel. Please read the documentation of gptel for more configuration details and provide the method to configure OpenAI here.
Procure an OpenAI API key.
Setup a key:
-
Recommend: Storing in ~/.authinfo. By default, “api.openai.com” is used as HOST and “apikey” as USER.
machine api.openai.com login apikey password TOKEN
-
Another: Set
gptel-api-key
to the key.
Activate magit-gptcommit-mode
. Then open a Magit status buffer, Commit message will automatically generated when staged changed. or run magit-gptcommit-generate'
to generate message manually.
Setup example using use-package and straight
(use-package magit-gptcommit
:straight t
:demand t
:after gptel magit
:config
;; Enable magit-gptcommit-mode to watch staged changes and generate commit message automatically in magit status buffer
;; This mode is optional, you can also use `magit-gptcommit-generate' to generate commit message manually
;; `magit-gptcommit-generate' should only execute on magit status buffer currently
;; (magit-gptcommit-mode 1)
;; Add gptcommit transient commands to `magit-commit'
;; Eval (transient-remove-suffix 'magit-commit '(1 -1)) to remove gptcommit transient commands
(magit-gptcommit-status-buffer-setup)
:bind (:map git-commit-mode-map
("C-c C-g" . magit-gptcommit-commit-accept))
)
Command | Description |
---|---|
magit-gptcommit-generate |
Generate gptcommit message and insert it into magit buffer. |
magit-gptcommit-commit-create |
Execute `magit-commit-create' and bring gptcommit message to editor. |
magit-gptcommit-commit-quick |
Accept gptcommit message and make a commit with current staged. |
magit-gptcommit-commit-accept |
Call on COMMIT_EDITMSG buffer, Accept gptcommit message after saving current message. |
magit-gptcommit-abort |
Abort the query process of current Repository. |
magit-gptcommit-remove-section |
Remove the gptcommit section from the current magit buffer. |
Variable | Description |
---|---|
magit-gptcommit-prompt |
Prompt. |
magit-gptcommit-max-token |
Default 4096, magit-gptcommit will truncate excessive characters based on 1 token = 4 chars |
magit-gptcommit-cache-limit |
Cache size, default is 30 |
magit-gptcommit--cache |
Cache of last generated commit message. |
- Prompt optimization
- There is still a lot of room for optimization. One problem is the context limitation, for example, GPT3.5 has a 4k context limit, so making a slightly larger edit will exceed the limit. Currently, the code roughly truncates the edit based on proportions to avoid this problem.
- Alternatively, we could use a method similar to gptcommit. This method summarizes the diff of each file and then merges all the summaries to generate the commit message. However, this approach requires n + 2 requests to generate a single message.
- LRU Cache or Disk Cache
- NO Stream
- Other LLM Support
- gptel Great project.
- gptcommit Very helpful, Prompt modified from this project.
- magit-todos This project has been of great help to me in learning magit development.
- GPT-Commit: Another Emacs pacakge for a similar purpose.