How to convert Java file to Kotlin with proper git history in Android Studio
Note: Below explained solution is not a solution of mine but rather given advice from a colleague.
- git mv
<source>.java
<destination>.kt
- Cut and paste whole content (java code) of the .kt file to different place (E.g. Sublime, Atom, or any other editor)
- Copy content from the new place (where you just pasted you java code)
- Paste to .kt file from clipboard and you should see below dialog. Just click yes and Android Studio will automatically convert your Java code to Kotlin. Most of the time it works fine but there are times when it can fail. But you could just simply fix those errors manually if that is the case
- git commit -am"Converted
<source>.java
to<destination>.kt
" (You can put whatever git message you would like to put) - git push origin
- Done. Now when you create pull request Java code will look like entirely deleted file and new Kotlin code will look like newly create/added. Then you can compare two files side by side.
I would like to know if someone has figured out even better solution for this. Please comment below for your suggestions/ideas