Automatic ghost commit when renaming file

Answered

So I was fixing up some code review findings in a kotlin project. One of those findings was an interface accidentally created as a Java file instead of a Kotlin file (old habits die hard I guess…)

I went ahead and created a commit with my changes. When pushing, I was surprised by a commit under my name with a commit message of “Rename .java to .kt” just one second before the commit I created. This is weird, since I certainly didn't write this commit message, nor did I try to create two commits. Also, the commit message doesn't abide by our commit message format, but this is beside the point. The content of this commit is what you'd expect - the renaming of this file (but not the changes within the file, these were added to my manually created commit).

Does anyone have an idea how this happened? I don't have any relevant plugins concerning git installed. I did find https://plugins.jetbrains.com/plugin/26995-git-explicit-rename-commit but I don't have it installed. Is this some default behaviour I didn't know about?

0
2 comments
Thanks for reaching out.

This is expected behavior in IntelliJ IDEA. When you convert a Java file to Kotlin, the IDE automatically creates a separate commit with the message "Rename .java to .kt" just before your main commit. This is intentional: Git needs a dedicated rename commit to properly track file history across the rename, so that `git log --follow` continues working on the `.kt` file.

If you would rather skip this extra commit, you can disable it:

1. Open the Git commit dialog (**Git | Commit** or `Ctrl+K`)
2. Find the **"Create extra commit with .java → .kt file rename"** checkbox
3. Uncheck it to prevent the automatic rename commit from being created

There is a feature request to allow customizing the auto-generated commit message: [IJPL-239359](https://youtrack.jetbrains.com/issue/IJPL-239359). You can follow or vote for it to receive updates and increase its priority.

Let us know if this helps.
0

Thanks for the answer, I will disable this feature

0

Please sign in to leave a comment.