You know that sometimes in rare cases a developer decides to restructure his project packaging structure. When it comes to this, managing this task is quiet a cool smooth process if you only do it within Android Studio, and for example you can follow the steps in this solution which worked amazingly great for me : Package Renaming Android Studio
However if you do this while you are in a team and you are using bitbucket and git commands for instance, this turn out to be quiet a delicate matter.
In my case, I proceeded to package renaming using Android Studio in a first step. The Renaming was successful until my task has been reviewed and rejected because in bitbucket, when selecting Show diff of => all changes in this pull request, well, all the files in the project are not marked as MOVED or MODIFIED ,but actually marked as DELETED and ADDED.
So to avoid any unwanted consequences such as loosing file history, I proceeded to the renaming of the package via Git Command line which are detailed in the following steps :
- cd parent_folder (package_to_be_renamed)
- git mv package_to_be_renamed new_package_name
and if you want to add a sub package within you package
- cd parent_package (package_to_be_renamed)
- mkdir new_package_name
- git add new_package_name (note git won't add an empty folder in the repository)
- git mv child_package new_package_name
- pwd result => parent_package/new_package_name/child_package
And to fix the project error don't forget to rename your package file by replacing the old package by the new one. for example, in Android Studio : cmd+shift+r => replace parent_package.child_package with parent_package.new_package_name.child_package
Once pushing these changes bitbucket show again all the files as DELETED and ADDED, while when selecting the commit they are shown as MOVED..
So to make sure that everything is fine I created a branch from the master (master-test-renaming) and merged my repackaging_branch into this new branch. The result: project working FINE with the new Package name. And history files are still trackable in Android Studio Git, show history.
Now my question is : Why bitbucket displays the files as deleted and added (when selecting Show diff of => all changes in this pull request) ???