Generate a git commit message for the current Java changes. Use the Conventional Commits format tailored to Java/Spring projects.
Step 1 — Gather context
Run (or ask Claude to run): git diff --staged --stat to see which files changed.
If nothing is staged, check git diff --stat for unstaged changes.
Step 2 — Analyse the changes
Based on the changed files, determine:
- Type of change: feat, fix, refactor, test, docs, chore, perf, security
- Scope: the Java package, module, or layer affected (e.g.,
service, controller, repository, security)
- What changed: specific class names, method names, or behaviours
Step 3 — Generate commit message
Use this format:
<type>(<scope>): <imperative summary under 72 chars>
[optional body — what changed and why, not how]
[optional footer — breaking changes, issue references]
Java-specific type rules:
feat: new class, method, endpoint, or feature
fix: bug fix in logic, null check, exception handling
refactor: extract method, rename, restructure — no behaviour change
perf: N+1 fix, index added, caching, virtual threads
test: new or updated JUnit/Mockito/Testcontainers tests
security: OWASP fix, auth change, secret handling improvement
chore: dependency update, build config, version bump
Java-specific scope examples:
user-service, order-controller, payment-repository
auth, security, jpa, api, dto
pom, gradle, ci
Examples:
feat(user-service): add findByEmail with case-insensitive search
Adds UserService.findByEmail() using Spring Data derived query.
Returns Optional<User> to handle missing users without null checks.
fix(order-controller): return 404 when order not found instead of 500
Previously threw NullPointerException when order ID did not exist.
Now throws ResourceNotFoundException mapped to 404 by GlobalExceptionHandler.
perf(product-repository): fix N+1 query with @EntityGraph on findAll
Each product was triggering a separate query for its category.
Added @EntityGraph(attributePaths = "category") to load in one JOIN.
refactor(auth-service): replace field injection with constructor injection
Removes @Autowired field injection on JwtTokenProvider and UserDetailsService.
Constructor injection makes dependencies explicit and improves testability.
Step 4 — Output
Provide:
- The commit message (ready to copy)
- The git command:
git commit -m "$(cat <<'EOF'\n[message]\nEOF\n)"
If multiple logical changes are staged together, suggest splitting into separate commits.
1---2name: java-commit3description: Generates a Conventional Commits message for staged Java changes. Use when user asks to "write a commit message", "help me commit", "what should my commit say", "summarize my changes", "draft a commit", or "create commit message".4---56Generate a git commit message for the current Java changes. Use the Conventional Commits format tailored to Java/Spring projects.78## Step 1 — Gather context9Run (or ask Claude to run): `git diff --staged --stat` to see which files changed.10If nothing is staged, check `git diff --stat` for unstaged changes.1112## Step 2 — Analyse the changes13Based on the changed files, determine:14- **Type of change**: feat, fix, refactor, test, docs, chore, perf, security15- **Scope**: the Java package, module, or layer affected (e.g., `service`, `controller`, `repository`, `security`)16- **What changed**: specific class names, method names, or behaviours1718## Step 3 — Generate commit message1920Use this format:21```22<type>(<scope>): <imperative summary under 72 chars>2324[optional body — what changed and why, not how]2526[optional footer — breaking changes, issue references]27```2829### Java-specific type rules:30- `feat`: new class, method, endpoint, or feature31- `fix`: bug fix in logic, null check, exception handling32- `refactor`: extract method, rename, restructure — no behaviour change33- `perf`: N+1 fix, index added, caching, virtual threads34- `test`: new or updated JUnit/Mockito/Testcontainers tests35- `security`: OWASP fix, auth change, secret handling improvement36- `chore`: dependency update, build config, version bump3738### Java-specific scope examples:39- `user-service`, `order-controller`, `payment-repository`40- `auth`, `security`, `jpa`, `api`, `dto`41- `pom`, `gradle`, `ci`4243### Examples:44```45feat(user-service): add findByEmail with case-insensitive search4647Adds UserService.findByEmail() using Spring Data derived query.48Returns Optional<User> to handle missing users without null checks.49```50```51fix(order-controller): return 404 when order not found instead of 5005253Previously threw NullPointerException when order ID did not exist.54Now throws ResourceNotFoundException mapped to 404 by GlobalExceptionHandler.55```56```57perf(product-repository): fix N+1 query with @EntityGraph on findAll5859Each product was triggering a separate query for its category.60Added @EntityGraph(attributePaths = "category") to load in one JOIN.61```62```63refactor(auth-service): replace field injection with constructor injection6465Removes @Autowired field injection on JwtTokenProvider and UserDetailsService.66Constructor injection makes dependencies explicit and improves testability.67```6869## Step 4 — Output70Provide:711. The commit message (ready to copy)722. The git command: `git commit -m "$(cat <<'EOF'\n[message]\nEOF\n)"`7374If multiple logical changes are staged together, suggest splitting into separate commits.