46

I need to change the case of folders and files. First thing I tried was renaming the folders, but Git didn't pick up the changes. So I tried using git mv -f controller Controller but it says :

fatal: renaming 'application/classes/controller failed: Permission denied

I have tried setting the global ignorecase flag:

git config --global core.ignorecase false

But it still doesn't work. Some people have suggested to move the folder out of repo, delete, then re-add but would this change get picked up when other people pull the repo? Is there anything else I could try?

Edit: It works for files but not folders.

Community
  • 1
  • 1
xylar
  • 7,433
  • 17
  • 55
  • 100
  • 11
    The Permission denied could simply come from the fact that you have an explorer window or command line client that has this folder as the current directory and thus prevents renaming. Make sure this is not the case and try again. – Daniel Hilgarth Jan 29 '13 at 08:49
  • 3
    The problem is that the Windows file system really is case-preserving. Moving `controller` to `Controller` would move it into itself. Probably the solution is to move it to a temporary, and then to the correct name. Or use a decent OS ;-) – Michael Wild Jan 29 '13 at 09:28
  • 1
    @MichaelWild NTFS is case-preserving, and it can handle case-altering renames perfectly fine. There has to be something else blocking things, likely some Explorer window as Daniel suggested. – Barend Jan 29 '13 at 09:33
  • 1
    Possibly it's a problem in the way that `git-mv` (or probably the lower-level MSYS or even CRT libraries) implements the rename. I just tried here, and the rename also failed. However, using a temporary worked just fine. – Michael Wild Jan 29 '13 at 09:39
  • 1
    The problem appears to be when moving folders. Changing the case of a file works. – xylar Jan 29 '13 at 09:51

4 Answers4

81

In summary of the comments, you'll have to rename the directory via a intermediate temporary name. E.g.

git mv controller Controller-tmp
git mv Controller-tmp Controller

I think this has to do with the fact that the MinGW implementation of rename(2) does not support this operation. See this thread, the MSDN docs on the CRT rename implementation and those of the MoveFileEx function.

Michael Wild
  • 24,977
  • 3
  • 43
  • 43
17

Make sure to close Visual Studio and any Windows Explorer folders related to that path.

Oren Bengigi
  • 994
  • 9
  • 17
  • I didn't have any files in the directory to be renamed open so I thought I was ok. But, VSCode was still using it in some way. Closing VSCode worked for me. – Ders Oct 26 '20 at 15:18
0

Make sure to add the changes to index after rename folder with intermediate folder as below.

git mv oldfolder newfolder

git add -u newfolder

git commit -m "changed the foldername whaddup"

Reference

Dulitha K
  • 2,088
  • 1
  • 19
  • 18
  • In my experience, `git mv` already does the staging. Was this with an older version? (2014...) – xtofl Feb 25 '16 at 15:14
0

I could not resolve this apart from performing the following

  1. Branch from commit before folder name case changed, as a temp branch just to resolve this issue.
  2. Cherry picking commits in order resolving folder case name changes before committing.
  3. Reset old branch this new temp branch final commit.
  4. Remove temp branch.
Jay Byford-Rew
  • 5,736
  • 1
  • 35
  • 36