Gitmit generates Conventional Commit messages by combining git diff parsing, heuristic analysis, weighted scoring, and template selection. The pipeline is fully offline and deterministic, with optional AI as a separate layer.
Git status/diff → Parser → Analyzer → Templater → Formatter → Commit message
Location: internal/parser/git.go
- Staged file discovery:
git status --porcelainis scanned to identify staged files and their actions (A/M/D/R/C). - Per-file diff extraction: For each staged file,
git diff --cached -U0 -- <file>is streamed. - Line stats: Added/removed lines are counted by diff prefixes (
+/-). - Major change flag: A file is marked
IsMajorwhen added+removed lines ≥ 500.
The parser returns a list of Change objects and aggregates totals for diff-stat analysis.
Location: internal/analyzer/analyzer.go
- Topic is inferred from directory path with configurable overrides (
topicMappings). - Item defaults to the filename without extension.
- Purpose is inferred from keyword mappings and built-in keyword heuristics.
Regex-based extraction detects structures from added lines:
- Functions (Go, JS/TS, Python, Java)
- Structs/Classes
- Methods (receiver-based Go methods)
These symbols are used to populate {item} placeholders and improve specificity.
Single-file patterns include:
- error handling, tests, imports, docs/comments, refactors
- API/database/performance/security indicators
- validation, logging, middleware, DI, CLI changes
Across all changes, Gitmit detects patterns such as:
- feature-addition (many new files)
- bug-fix-cascade (many modified files with fix keywords)
- refactor-sweep (mixed A/M/D)
- test-suite-update / config-update
- api-redesign / database-migration
Early exits provide deterministic messages for clear cases:
- Single added file →
feat - Single deleted file →
chore - Only docs/config/deps →
docs/ci/chore(deps)
The commit action is determined by a weighted score map, with support for normalized confidence weights (default).
Gitmit uses normalized confidence weights to reduce noise when multiple signals compete.
- Normalize signals (0–1):
- Branch hint: 1.0 if branch name matches an action, 0.0 otherwise.
- Diff-stat: 0–1 based on distance from thresholds (added/removed ratio).
- Keywords: Raw keyword scores are normalized relative to the highest-scoring action.
- Multi-file patterns: 1.0 if a relevant pattern is detected, 0.0 otherwise.
- Apply confidence weights:
- branch: 0.35
- diff-stat: 0.25
- keywords: 0.25
- multi-file patterns: 0.15
- Final score:
sum(weight × normalized_signal)per action. - Selection: The action with the highest final score is selected.
- Fallback: If top action score < 0.35, Gitmit falls back to file-based heuristics.
If normalizeScoring is disabled in config, Gitmit falls back to raw score aggregation:
- Branch name hints: +3 to matching action.
- Diff-stat ratio: +2 to
featorrefactor. - Keyword scoring: per-action weights are added directly.
- Multi-file patterns: +3 or +4 to relevant actions.
- Single topic → that topic
- Single directory → directory name
- 2–3 topics → combined scope (sorted)
- Many topics → most common or
core - Commit history can override scope when consistent across recent commits
Location: internal/templater/templater.go
- Template group resolution: action → template group (A/M/D/R/DOC/SECURITY/MISC).
- Topic match: exact → fuzzy →
_default. - Template scoring:
- Base score 1.0
- +2.0 for matching detected patterns
- +1.5 for using detected symbols
- +1.0 for meaningful purpose placeholders
- +0.5–1.5 for file-type relevance
- +1.0 for major change templates
- -0.5 for generic templates when specifics exist
- History de-dup: recent messages are avoided when possible.
The highest-scoring template is selected, and placeholders ({topic}, {item}, {purpose}, {source}, {target}) are replaced.
When regenerating suggestions:
- Used messages are filtered out.
- Similarity is computed using:
- Word-level Jaccard similarity (60%)
- Character position matching (40%)
- A diversity bonus favors less similar suggestions.
- A small random factor introduces controlled variation.
Location: internal/config/config.go + docs/CONFIGURATION.md
Configuration can adjust:
- Topic mappings
- Keyword mappings and weights
- Diff-stat thresholds
- Project-specific defaults
This allows the algorithm’s weighting to be tuned without code changes.