Skip to content

Commit 424b011

Browse files
committed
chore(docs): update project-specific commit message guidelines in README and example file
1 parent 067db72 commit 424b011

6 files changed

Lines changed: 115 additions & 16 deletions

File tree

COMMIT_MESSAGE.md.example

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Commit Message Guidelines
2+
3+
This file provides project-specific context for AI-generated commit messages.
4+
Place this file as `COMMIT_MESSAGE.md` in one of these locations (searched in order):
5+
1. Project root directory
6+
2. `.git/` directory
7+
3. `.github/` directory
8+
9+
## Project Context
10+
11+
This is a git commit history rewriter tool that helps developers improve their commit messages using AI.
12+
13+
## Commit Message Requirements
14+
15+
- Always use conventional commit format: `type(scope): description`
16+
- Types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert
17+
- Scopes for this project: cli, hooks, providers, core, docs
18+
- Keep the first line under 72 characters
19+
- Write in present tense ("add" not "added")
20+
- Focus on what and why, not how
21+
22+
## Project-Specific Guidelines
23+
24+
- When changing git hooks, mention which hooks are affected
25+
- When updating providers, specify which AI provider (OpenAI/Ollama)
26+
- Security-related changes should be clearly marked
27+
- Breaking changes should include BREAKING CHANGE in the message
28+
29+
## Examples
30+
31+
Good commit messages for this project:
32+
- `feat(hooks): add support for custom Ollama server URLs`
33+
- `fix(core): prevent console output from contaminating commit messages`
34+
- `docs(readme): add blog post link and improve security section`
35+
- `refactor(providers): split provider implementations into separate files`
36+
37+
## Additional Notes
38+
39+
- This tool is security-sensitive as it handles git history
40+
- Consider privacy implications when mentioning data handling
41+
- Emphasize user control and opt-in features

README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ ollama serve
7373
- **Efficient processing** - Process only the last N commits with `--max-commits`
7474
- **Dry-run mode** - Preview changes before applying them
7575
- **Progress tracking** - Real-time progress indicators with colored output
76+
- **Custom context** - Project-specific guidelines via `COMMIT_MESSAGE.md` file
7677

7778
## Installation
7879

@@ -161,41 +162,66 @@ git config hooks.providerModel "gpt-4" # or "gpt-3.5-turbo", "llama3.2", etc.
161162
git config hooks.ollamaUrl "http://192.168.1.100:11434"
162163
```
163164

165+
### Custom Project Guidelines with `COMMIT_MESSAGE.md`
166+
167+
You can provide project-specific commit message guidelines that the AI will follow by creating a `COMMIT_MESSAGE.md` file. The tool searches for this file in the following locations (in order):
168+
169+
1. **Project root** - `./COMMIT_MESSAGE.md`
170+
2. **Git directory** - `./.git/COMMIT_MESSAGE.md`
171+
3. **GitHub directory** - `./.github/COMMIT_MESSAGE.md`
172+
173+
Example `COMMIT_MESSAGE.md`:
174+
```markdown
175+
# Project Commit Guidelines
176+
177+
## Requirements
178+
- Use conventional commits with these scopes: auth, api, ui, db
179+
- Include ticket numbers when available (e.g., JIRA-123)
180+
- Security changes must be clearly marked
181+
- Breaking changes need BREAKING CHANGE in the message
182+
183+
## Project Context
184+
This is a financial services API that handles sensitive data.
185+
Emphasize security, compliance, and performance in commit messages.
186+
```
187+
188+
See [`COMMIT_MESSAGE.md.example`](COMMIT_MESSAGE.md.example) in this repository for a complete example.
189+
164190
## Usage
165191

166192
### Command Examples
167193

168194
```bash
169195
# Using the full command name
170-
git-rewrite-commits [options]
196+
npx git-rewrite-commits [options]
171197

172198
# Or using the short alias (grec)
173-
grec [options]
199+
npx grec [options]
174200
```
175201

176202
Common use cases:
177203

178204
```bash
179205
# Rewrite entire git history
180-
grec
206+
npx git-rewrite-commits
181207

182208
# Preview changes without applying (dry run)
183-
grec --dry-run
209+
npx git-rewrite-commits --dry-run
184210

185211
# Generate commit message for staged changes
186-
grec --staged
212+
npx git-rewrite-commits --staged
187213

188214
# Process only last 10 commits
189-
grec --max-commits 10
215+
npx git-rewrite-commits --max-commits 10
190216

191217
# Use custom AI model
192-
grec --model gpt-4
218+
npx git-rewrite-commits --model gpt-4
193219

194220
# Use local AI with Ollama
195-
grec --provider ollama
221+
npx git-rewrite-commits --provider ollama
196222

197223
# Install/update git hooks
198-
grec --install-hooks
224+
npx git-rewrite-commits --install-hooks
199225
```
200226

201227
## Real-World Examples

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "git-rewrite-commits",
3-
"version": "0.7.2",
3+
"version": "0.7.3",
44
"description": "AI-powered git commit message rewriter using OpenAI - rewrite your entire git history with better conventional commit messages",
55
"type": "module",
66
"main": "./dist/index.js",

packages/grec/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "grec",
3-
"version": "0.7.2",
3+
"version": "0.7.3",
44
"description": "Short alias for git-rewrite-commits - AI-powered git commit message rewriter",
55
"type": "module",
66
"bin": {
@@ -34,7 +34,7 @@
3434
"node": ">=16.0.0"
3535
},
3636
"dependencies": {
37-
"git-rewrite-commits": "^0.7.2"
37+
"git-rewrite-commits": "^0.7.3"
3838
},
3939
"publishConfig": {
4040
"access": "public"

src/index.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,35 @@ export class GitCommitRewriter {
310310
return redacted;
311311
}
312312

313+
private findCommitMessageContext(): string | null {
314+
// Search for COMMIT_MESSAGE.md in order of priority:
315+
// 1. Current root directory
316+
// 2. .git directory
317+
// 3. .github directory
318+
const searchPaths = [
319+
path.join(process.cwd(), 'COMMIT_MESSAGE.md'),
320+
path.join(process.cwd(), '.git', 'COMMIT_MESSAGE.md'),
321+
path.join(process.cwd(), '.github', 'COMMIT_MESSAGE.md'),
322+
];
323+
324+
for (const filePath of searchPaths) {
325+
try {
326+
if (fs.existsSync(filePath)) {
327+
const content = fs.readFileSync(filePath, 'utf-8');
328+
if (this.options.verbose && !this.options.quiet) {
329+
console.log(chalk.blue(`📝 Found custom commit message context at: ${path.relative(process.cwd(), filePath)}`));
330+
}
331+
return content.trim();
332+
}
333+
} catch (error) {
334+
// Continue searching if file can't be read
335+
continue;
336+
}
337+
}
338+
339+
return null;
340+
}
341+
313342
private async generateCommitMessage(
314343
diff: string,
315344
files: string[],
@@ -319,6 +348,9 @@ export class GitCommitRewriter {
319348
// Redact sensitive data from diff before sending to AI provider
320349
const redactedDiff = this.redactSensitivePatterns(diff);
321350

351+
// Look for custom commit message context
352+
const customContext = this.findCommitMessageContext();
353+
322354
let formatInstructions = '';
323355

324356
if (this.options.template) {
@@ -350,7 +382,7 @@ Example: If template is "[JIRA-XXX] type: message", generate something like "[JI
350382
// User provided custom prompt - use it with basic context
351383
prompt = `You are a git commit message generator. Analyze the following git diff and file changes, then ${this.options.prompt}
352384
353-
Old commit message: "${oldMessage}"
385+
${customContext ? `Project-specific guidelines:\n${customContext}\n\n` : ''}Old commit message: "${oldMessage}"
354386
355387
Files changed:
356388
${files.join('\n')}
@@ -366,7 +398,7 @@ Return ONLY the commit message, nothing else.`;
366398
// Use default prompt with all standard instructions
367399
prompt = `You are a git commit message generator. Analyze the following git diff and file changes, then generate a clear, concise commit message.
368400
369-
Old commit message: "${oldMessage}"
401+
${customContext ? `Project-specific guidelines:\n${customContext}\n\n` : ''}Old commit message: "${oldMessage}"
370402
371403
Files changed:
372404
${files.join('\n')}

0 commit comments

Comments
 (0)