gitdirectory-structurefile-rename

Git issue when renaming directory


I know the answer to this question has been answered in dozen of SO questions but I'm still getting an issue.

I've followed the steps from this: In a Git repository, how to properly rename a directory?

I have a Laravel project using Vue in the frontend. The structure is roughly as:

- /Components
- /Layouts
  - /Components
  - Layout1.vue
  - Layout2.vue
- /Pages
- /Shared
  - /Components

We want to update it to:

- /components  <= moving /Shared/Components here as well
- /layouts
  - /partials
  - Layout1.vue
  - Layout2.vue
- /pages

The suggestion is to use a 2 steps process:

git mv casesensitive tmp
git mv tmp CaseSensitive

I've tried that but didn't work. When trying to merge/checkout/switch/cherry-pick/rebase to another branch, I keep getting the following error:

error: The following untracked working tree files would be overwritten by checkout:
    resources/js/Components/Notifications.vue
    resources/js/Components/PhoneCodeConfirmation.vue
    resources/js/Components/SMSCredit.vue
Please move or remove them before you switch branches.
Aborting

So instead, I've tried to commit my changes and push them after the first step:

git mv resources/js/Components resources/js/components_temp
git commit -am "updated to temporary folder name"
git push

At this point, it works because the folder name is completely different. Then I'm doing the final renaming:

git mv resources/js/components_temp resources/js/components
git commit -am "updated to lowercase folder name"
git push

It pushes correctly. However, I'm still getting the same error following untracked working tree files would be overwritten by checkout.

Anyone having any idea why ?

EDIT This is happening to any folders that I rename to a lowercase version. The 2 steps process does not prevent it. It's like if my git working tree was still keeping track of old name, even after doing the steps above


Solution

  • Since all solutions I found online didn't seems to work for me, I've used the following workaround to make it work. I copied everything to a new path:

    cp -R resources/js resources/app
    

    I was then able to rename every directories/files inside that new folder the way I wanted. All I had to do then was to remove the old one and add the new one:

    git rm resources/js
    git add resources/app
    

    (I also had to point my app to the new path but that's easy). The only frustrating part in all of this, is that I still don't know why it didn't work and why it is so complicated to rename a directory in git on Mac.