Problem
After converting a Java file to Kotlin (Code | Convert Java File to Kotlin File or Ctrl+Alt+Shift+K) and committing through the IDE's Commit tool window, two commits appear in Git history instead of one:
- An automatically generated commit with the hardcoded message
Rename .java to .kt. - The user's commit with the message entered in the Commit tool window.
When the repository has a commit-msg Git hook that enforces a custom format (for example, Conventional Commits via commitlint), the hook rejects the auto-generated Rename .java to .kt commit and the push or commit fails.
Cause
This is intentional behavior. To preserve file history across the language change, IntelliJ IDEA's ConvertLanguageExplicitMovementProvider splits the conversion into a dedicated rename-only commit followed by the content commit. The split allows git log --follow and rename detection to keep working on the new .kt file.
The auto-generated commit message is hardcoded and is not currently exposed in Settings | Version Control | Git or via the Registry. A feature request to allow customizing it is tracked in IJPL-239359.
Resolution
Option 1: Disable the extra rename commit
The Commit tool window contains an option that controls this behavior:
- Open the Commit tool window (Git | Commit or Ctrl+K).
- Locate the Create extra commit with .java → .kt file rename checkbox under the Show Commit Options submenu (cogwheel button). The checkbox appears only when the change set includes a Java-to-Kotlin conversion.
- Clear the checkbox.
- Commit again. The conversion is committed as a single commit using the message from the Commit tool window.
Trade-off: Git no longer records the change as a rename. The .java file appears as a deletion and the .kt file as an addition, so git log --follow and rename-aware blame on the new file lose continuity.
Option 2: Allow the rename commit message in the hook
If preserving rename history is required, add an exception for the auto-generated message in the commit-msg hook.
For commitlint, add an ignores rule in commitlint.config.js:
module.exports = {
extends: ['@commitlint/config-conventional'],
ignores: [(message) => /^Rename \.\w+ to \.\w+$/.test(message)],
};
For a custom shell-based hook, skip validation when the message matches the rename pattern:
if grep -qE '^Rename \.[a-z]+ to \.[a-z]+$' "$1"; then
exit 0
fi
Option 3: Rename and convert outside the IDE commit flow
- Convert the file via Code | Convert Java File to Kotlin File.
- Commit the rename from the terminal with a message that satisfies the hook:
git add -A git commit -m "chore: rename .java to .kt" - Make subsequent edits and commit them separately through the IDE.
Related issue
IJPL-239359 — feature request to allow customizing the auto-generated commit message used during Java-to-Kotlin conversion.
Comments
0 comments
Please sign in to leave a comment.