The git-context tool generates essential git-related context to help LLMs create meaningful commit messages. This simplified version focuses on providing only the most useful information for commit message generation.
./git-context [options] > commit_context.txt| Argument | Description | Default |
|---|---|---|
--recent-commits=<num> |
Show most recent N commits for context | 3 |
--prompt=<file> |
Use custom commit message prompt from file | "prompts/commit_prompt.txt" |
--no-prompt |
Don't include commit message prompt | False |
The tool outputs git context information in markdown format, which includes:
- Git status summary
- Git diff of uncommitted changes against HEAD
- List of files changed with their status
- Recent commit messages for style reference
- Commit message guidance from prompts/commit_prompt.txt
Generate context for a commit message:
./git-context > commit_context.txtUse the conventional commits format guidance included in the repository:
./git-context --prompt=prompts/conventional_commit.txt > commit_context.txtThis uses the pre-defined conventional commit format guidance from the prompts directory.
Generate context without the commit message guidance:
./git-context --no-prompt > commit_context.txtShow more or fewer recent commits:
./git-context --recent-commits=5 > commit_context.txtThe commit message prompt template is stored in prompts/commit_prompt.txt and can be customized to your project's needs.
For conventional commits or other specialized formats, create a custom prompt file and specify it with the --prompt= option.
Typical workflow:
- Make changes to your code
- Run
./git-context > commit_context.txt - Send commit_context.txt to an LLM to generate a commit message
- Use the generated message with
git commit -m "generated message"
# Generate commit message and use it directly (using an LLM CLI tool)
git commit -am "$(./git-context | llm -m openrouter/anthropic/claude-3.5-haiku)"
# Generate commit message but edit it before committing
git commit -am "$(./git-context | llm -m openrouter/anthropic/claude-3.5-haiku)" -e
# Generate a conventional commit message with editing option
git commit -am "$(./git-context --prompt=prompts/conventional_commit.txt | llm -m openrouter/anthropic/claude-3.5-haiku)" -eThe -e or --edit option opens the commit message in your default editor, allowing you to review, edit, or cancel the commit if needed.