|
1 | 1 | --- |
2 | 2 | name: generating-commit-messages |
3 | | -description: This skill provides AI-powered git commit message generation using the `codegpt commit` command. It analyzes git diffs and automatically generates conventional commit messages in multiple languages. |
| 3 | +description: Automatically generates conventional commit messages by analyzing your staged git changes using AI. Use this skill when you need to create well-formatted, meaningful commit messages that follow the Conventional Commits specification, or when you want to save time writing commit descriptions for your changes. |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # Generating Commit Messages |
7 | 7 |
|
8 | | -## Description |
| 8 | +## Step-by-Step Instructions |
9 | 9 |
|
10 | | -The git-commit skill leverages various AI providers (OpenAI, Anthropic, Gemini, Ollama, Groq, OpenRouter) to automatically generate meaningful commit messages that follow the [Conventional Commits](https://www.conventionalcommits.org/) specification. |
| 10 | +### Installation |
11 | 11 |
|
12 | | -## Installation |
| 12 | +1. Run the install script to download and set up CodeGPT: |
13 | 13 |
|
14 | | -Run the install script to automatically download and set up the latest release: |
| 14 | + ```bash |
| 15 | + bash < <(curl -sSL https://raw.githubusercontent.com/appleboy/CodeGPT/main/install.sh) |
| 16 | + ``` |
15 | 17 |
|
16 | | -```sh |
17 | | -bash < <(curl -sSL https://raw.githubusercontent.com/appleboy/CodeGPT/main/install.sh) |
18 | | -``` |
| 18 | +2. Configure your AI provider in `~/.config/codegpt/.codegpt.yaml`: |
19 | 19 |
|
20 | | -## Usage |
| 20 | + ```yaml |
| 21 | + openai: |
| 22 | + provider: openai # or: azure, anthropic, gemini, ollama, groq, openrouter |
| 23 | + api_key: your_api_key_here |
| 24 | + model: gpt-4o |
| 25 | + ``` |
21 | 26 |
|
22 | 27 | ### Basic Usage |
23 | 28 |
|
24 | | -Generate a commit message for staged changes (Skip confirmation prompts): |
| 29 | +1. Stage your changes: |
| 30 | +
|
| 31 | + ```bash |
| 32 | + git add <files> |
| 33 | + ``` |
| 34 | + |
| 35 | +2. Generate and commit with AI-generated message: |
| 36 | + |
| 37 | + ```bash |
| 38 | + codegpt commit --no_confirm |
| 39 | + ``` |
| 40 | + |
| 41 | +3. Or preview the message before committing: |
| 42 | + |
| 43 | + ```bash |
| 44 | + codegpt commit --preview |
| 45 | + ``` |
| 46 | + |
| 47 | +### Advanced Options |
| 48 | + |
| 49 | +- **Set language**: Use `--lang` to specify output language (en, zh-tw, zh-cn) |
| 50 | + |
| 51 | + ```bash |
| 52 | + codegpt commit --lang zh-tw |
| 53 | + ``` |
| 54 | + |
| 55 | +- **Use specific model**: Override the default model |
| 56 | + |
| 57 | + ```bash |
| 58 | + codegpt commit --model gpt-4o |
| 59 | + ``` |
| 60 | + |
| 61 | +- **Exclude files**: Ignore certain files from the diff analysis |
| 62 | + |
| 63 | + ```bash |
| 64 | + codegpt commit --exclude_list "*.lock,*.json" |
| 65 | + ``` |
| 66 | + |
| 67 | +- **Custom templates**: Format messages according to your team's style |
| 68 | + |
| 69 | + ```bash |
| 70 | + codegpt commit --template_string "[{{.summarize_prefix}}] {{.summarize_title}}" |
| 71 | + ``` |
| 72 | + |
| 73 | +- **Amend commit**: Update the previous commit message |
| 74 | + |
| 75 | + ```bash |
| 76 | + codegpt commit --amend |
| 77 | + ``` |
| 78 | + |
| 79 | +## Examples of Inputs and Outputs |
| 80 | + |
| 81 | +### Example 1: Adding a new feature |
| 82 | + |
| 83 | +**Input:** |
25 | 84 |
|
26 | 85 | ```bash |
| 86 | +# After making changes to add user authentication |
| 87 | +git add src/auth.go src/middleware.go |
27 | 88 | codegpt commit --no_confirm |
28 | 89 | ``` |
29 | 90 |
|
30 | | -### Common Options |
| 91 | +**Output:** |
| 92 | + |
| 93 | +```txt |
| 94 | +feat: add user authentication middleware |
| 95 | +
|
| 96 | +Implement JWT-based authentication system with login and token validation |
| 97 | +middleware for protecting API endpoints. |
| 98 | +``` |
| 99 | + |
| 100 | +### Example 2: Fixing a bug |
| 101 | + |
| 102 | +**Input:** |
31 | 103 |
|
32 | 104 | ```bash |
33 | | -# Preview commit message before committing |
| 105 | +# After fixing a null pointer error |
| 106 | +git add src/handlers/user.go |
34 | 107 | codegpt commit --preview |
| 108 | +``` |
35 | 109 |
|
36 | | -# Skip confirmation prompts |
37 | | -codegpt commit --no_confirm |
| 110 | +**Output:** |
38 | 111 |
|
39 | | -# Set output language (en, zh-tw, zh-cn) |
40 | | -codegpt commit --lang zh-tw |
| 112 | +```txt |
| 113 | +fix: resolve null pointer exception in user handler |
41 | 114 |
|
42 | | -# Use specific AI model |
43 | | -codegpt commit --model gpt-4o |
| 115 | +Add nil checks before accessing user object properties to prevent crashes |
| 116 | +when processing requests with missing user data. |
44 | 117 |
|
45 | | -# Amend previous commit |
46 | | -codegpt commit --amend |
| 118 | +[Preview shown, waiting for confirmation...] |
| 119 | +``` |
47 | 120 |
|
48 | | -# Display prompt only (no API call) |
49 | | -codegpt commit --prompt_only |
| 121 | +### Example 3: Chinese language commit |
50 | 122 |
|
51 | | -# Write to specific output file |
52 | | -codegpt commit --file /path/to/commit-msg |
| 123 | +**Input:** |
53 | 124 |
|
54 | | -# Customize diff context lines |
55 | | -codegpt commit --diff_unified 5 |
| 125 | +```bash |
| 126 | +git add docs/README.md |
| 127 | +codegpt commit --lang zh-tw --no_confirm |
| 128 | +``` |
56 | 129 |
|
57 | | -# Exclude specific files from diff |
58 | | -codegpt commit --exclude_list "*.lock,*.json" |
| 130 | +**Output:** |
59 | 131 |
|
60 | | -# Use custom template file |
61 | | -codegpt commit --template_file ./my-template.tmpl |
| 132 | +```txt |
| 133 | +docs: 更新專案說明文件 |
62 | 134 |
|
63 | | -# Use inline template string |
64 | | -codegpt commit --template_string "{{.summarize_prefix}}: {{.summarize_title}}" |
| 135 | +新增安裝步驟說明以及使用範例,讓新使用者能夠快速上手。 |
| 136 | +``` |
65 | 137 |
|
66 | | -# Set API timeout |
67 | | -codegpt commit --timeout 60s |
| 138 | +### Example 4: Custom template with ticket number |
68 | 139 |
|
69 | | -# Configure network proxy |
70 | | -codegpt commit --proxy http://proxy.example.com:8080 |
71 | | -codegpt commit --socks socks5://127.0.0.1:1080 |
| 140 | +**Input:** |
| 141 | + |
| 142 | +```bash |
| 143 | +git add src/api/payment.go |
| 144 | +codegpt commit --template_string "{{.summarize_prefix}}(JIRA-123): {{.summarize_title}}" --no_confirm |
72 | 145 | ``` |
73 | 146 |
|
74 | | -### Template Variables |
| 147 | +**Output:** |
75 | 148 |
|
76 | | -When using custom templates, the following variables are available: |
| 149 | +```txt |
| 150 | +feat(JIRA-123): integrate payment gateway API |
| 151 | +``` |
77 | 152 |
|
78 | | -- `{{.summarize_prefix}}` - Conventional commit prefix (feat, fix, docs, etc.) |
79 | | -- `{{.summarize_title}}` - Brief commit title |
80 | | -- `{{.summarize_message}}` - Detailed commit message body |
| 153 | +### Example 5: Excluding lock files |
81 | 154 |
|
82 | | -You can also provide custom variables: |
| 155 | +**Input:** |
83 | 156 |
|
84 | 157 | ```bash |
85 | | -codegpt commit --template_vars "author=John,ticket=PROJ-123" |
86 | | -codegpt commit --template_vars_file ./vars.env |
| 158 | +git add . |
| 159 | +codegpt commit --exclude_list "package-lock.json,yarn.lock,go.sum" --preview |
87 | 160 | ``` |
88 | 161 |
|
89 | | -## Workflow |
| 162 | +**Output:** |
90 | 163 |
|
91 | | -1. **Diff Analysis**: Analyzes staged changes using `git diff` |
92 | | -2. **Summarization**: AI generates a summary of the changes |
93 | | -3. **Title Generation**: Creates a concise commit title |
94 | | -4. **Prefix Detection**: Determines appropriate conventional commit prefix |
95 | | -5. **Message Composition**: Combines all elements into a formatted message |
96 | | -6. **Translation** (optional): Translates to target language if specified |
97 | | -7. **Preview & Confirmation**: Shows message for review and optional editing |
98 | | -8. **Commit**: Records changes to the repository |
| 164 | +```txt |
| 165 | +refactor: reorganize project structure |
99 | 166 |
|
100 | | -## Configuration |
| 167 | +Move utility functions into separate packages and update import paths |
| 168 | +throughout the codebase for better modularity. |
101 | 169 |
|
102 | | -Configure via `~/.config/codegpt/.codegpt.yaml`: |
| 170 | +(Lock files excluded from analysis) |
| 171 | +``` |
103 | 172 |
|
104 | | -```yaml |
105 | | -openai: |
106 | | - provider: openai # or: azure, anthropic, gemini, ollama, groq, openrouter |
107 | | - api_key: your_api_key_here |
108 | | - model: gpt-4o |
109 | | - timeout: 30s |
| 173 | +## Common Edge Cases |
110 | 174 |
|
111 | | -git: |
112 | | - diff_unified: 3 |
113 | | - exclude_list: [] |
114 | | - template_file: "" |
115 | | - template_string: "" |
| 175 | +### No staged changes |
116 | 176 |
|
117 | | -output: |
118 | | - lang: en # or: zh-tw, zh-cn |
119 | | - file: "" |
| 177 | +**Issue**: Running `codegpt commit` without staging any changes. |
| 178 | + |
| 179 | +**Solution**: Stage your changes first: |
| 180 | + |
| 181 | +```bash |
| 182 | +git add <files> |
| 183 | +codegpt commit |
120 | 184 | ``` |
121 | 185 |
|
122 | | -## Examples |
| 186 | +### API timeout for large diffs |
| 187 | + |
| 188 | +**Issue**: Large changesets may cause API timeouts. |
123 | 189 |
|
124 | | -### Example 1: Basic commit without preview |
| 190 | +**Solution**: Increase timeout or commit changes in smaller batches: |
125 | 191 |
|
126 | 192 | ```bash |
127 | | -# Stage your changes |
128 | | -git add . |
| 193 | +codegpt commit --timeout 60s |
| 194 | +``` |
129 | 195 |
|
130 | | -# Generate commit message without confirmation |
131 | | -codegpt commit --no_confirm |
| 196 | +### Generated files in diff |
| 197 | + |
| 198 | +**Issue**: Lock files or generated code affecting commit message quality. |
| 199 | + |
| 200 | +**Solution**: Exclude these files from analysis: |
| 201 | + |
| 202 | +```bash |
| 203 | +codegpt commit --exclude_list "package-lock.json,yarn.lock,*.min.js,dist/*" |
132 | 204 | ``` |
133 | 205 |
|
134 | | -### Example 2: Chinese commit message |
| 206 | +### API key not configured |
| 207 | + |
| 208 | +**Issue**: Error message about missing API key. |
| 209 | + |
| 210 | +**Solution**: Set up your API key in the config file: |
135 | 211 |
|
136 | 212 | ```bash |
137 | | -codegpt commit --lang zh-tw --model gpt-4o --no_confirm |
| 213 | +codegpt config set openai.api_key "your-api-key-here" |
138 | 214 | ``` |
139 | 215 |
|
140 | | -### Example 3: Custom template |
| 216 | +### Custom commit format required |
| 217 | + |
| 218 | +**Issue**: Team requires specific commit message format (e.g., with ticket numbers). |
| 219 | + |
| 220 | +**Solution**: Use custom templates: |
141 | 221 |
|
142 | 222 | ```bash |
143 | | -codegpt commit \ |
144 | | - --template_string "[{{.summarize_prefix}}] {{.summarize_title}}" \ |
145 | | - --template_vars "ticket=PROJ-123" |
| 223 | +codegpt commit --template_string "[{{.summarize_prefix}}] TICKET-123: {{.summarize_title}}" |
146 | 224 | ``` |
147 | 225 |
|
148 | | -### Example 4: With file exclusions |
| 226 | +Or save it in config file: |
| 227 | + |
| 228 | +```yaml |
| 229 | +git: |
| 230 | + template_string: "[{{.summarize_prefix}}] {{.ticket}}: {{.summarize_title}}" |
| 231 | +``` |
| 232 | +
|
| 233 | +### Multilingual team |
| 234 | +
|
| 235 | +**Issue**: Need commit messages in different languages for different repositories. |
| 236 | +
|
| 237 | +**Solution**: Set language per command or configure per repository: |
149 | 238 |
|
150 | 239 | ```bash |
151 | | -codegpt commit \ |
152 | | - --exclude_list "package-lock.json,yarn.lock,go.sum" \ |
153 | | - --preview |
| 240 | +# Per command |
| 241 | +codegpt commit --lang zh-cn |
| 242 | + |
| 243 | +# Or set in repository's .codegpt.yaml |
| 244 | +output: |
| 245 | + lang: zh-cn |
154 | 246 | ``` |
155 | 247 |
|
156 | | -## Tips |
| 248 | +### Network proxy required |
| 249 | +
|
| 250 | +**Issue**: API calls fail due to corporate firewall. |
157 | 251 |
|
158 | | -1. **Stage Changes First**: Always run `git add` before using `codegpt commit` |
159 | | -2. **Use Preview Mode**: Review messages with `--preview` before committing |
160 | | -3. **Customize Templates**: Create templates that match your team's commit style |
161 | | -4. **Set Default Language**: Configure your preferred language in config file |
162 | | -5. **Exclude Generated Files**: Use `--exclude_list` to ignore lock files and generated code |
| 252 | +**Solution**: Configure proxy settings: |
| 253 | +
|
| 254 | +```bash |
| 255 | +codegpt commit --proxy http://proxy.company.com:8080 |
| 256 | +# Or for SOCKS proxy |
| 257 | +codegpt commit --socks socks5://127.0.0.1:1080 |
| 258 | +``` |
0 commit comments