1

In my git project, one of the developer changed the filename from all uppercase to CamelCase yesterday. in his feature branch and merged to master

I pulled the remote master. Now during any local git operation, git shows message for the file in uppsecase (old) as untracked. Whereas the file is in commit status in the mentioned folder & I never touched it on my local.

What I tried,

  • I tried to use git clean -fd to clear the untrack tree, but still the same error.
  • I tried to use git rm uupercaseFilename but command fails, name not match any file.
  • Futile attempt to git reset --hard HEAD.
  • I don't see ANY file in git status message is nothing to commit, working tree clean - Finally I had to manually delete the new with camel Case Name
  • checkout to my feature branch worked fine.

But now, if I do any operation in my feature-x branch, I'm again getting this error.

I can fix this by the manual deletion as I did above. But want to know if there's a correct way to handle this situation.

Below are all the exact commands I ran, with renamed file/project/packagenames

[gitbash] :: /c/repo/myrepo/myproject (master)
$ git clean -fd

[gitbash] :: /c/repo/myrepo/myproject (master)
$ git checkout feature-x
error: The following untracked working tree files would be overwritten by checkout:
        main/com/my/project/badfile//ALL_CAPS_NAME.java
Please move or remove them before you switch branches.
Aborting

[gitbash] :: /c/repo/myrepo/myproject (master)
$ git rm main/com/my/project/badfile//ALL_CAPS_NAME.java
fatal: pathspec 'main/com/my/project/badfile//ALL_CAPS_NAME.java' did not match any files

[gitbash] :: /c/repo/myrepo/myproject (master)
$ git rm ALL_CAPS_NAME.java
fatal: pathspec 'ALL_CAPS_NAME.java' did not match any files

[gitbash] :: /c/repo/myrepo/myproject (master)
$ git checkout feature-x
error: The following untracked working tree files would be overwritten by checkout:
        main/com/my/project/badfile//ALL_CAPS_NAME.java
Please move or remove them before you switch branches.
Aborting

[gitbash] :: /c/repo/myrepo/myproject (master)
$ git reset --hard HEAD
HEAD is now at 5f2918e3fd Merge branch 'feature-Y' into 'master'

[gitbash] :: /c/repo/myrepo/myproject (master)
$ git checkout feature-x
error: The following untracked working tree files would be overwritten by checkout:
        main/com/my/project/badfile//ALL_CAPS_NAME.java
Please move or remove them before you switch branches.
Aborting

[gitbash] :: /c/repo/myrepo/myproject (master)
$ cd main/com/my/project/badfile/

[gitbash] :: /c/repo/myrepo/myproject/main/com/my/project/badfile/ (master)
$ ls -lrt
total 12
-rwxr-xr-x 1 gitbash 1049089 1443 Jul 29 17:44 someOtherFile.java*
drwxr-xr-x 1 gitbash 1049089    0 Aug  1 23:01 config/
-rwxr-xr-x 1 gitbash 1049089 3847 Aug 11 12:48 All_Caps_Name.java*
-rwxr-xr-x 1 gitbash 1049089 2349 Aug 11 12:48 someOtherFile2.java*

[gitbash] :: /c/repo/myrepo/myproject/main/com/my/project/badfile/ (master)
$ rm All_Caps_Name.java

[gitbash] :: /c/repo/myrepo/myproject/main/com/my/project/badfile/ (master)
$ cd -
/c/repo/myrepo/myproject

[gitbash] :: /c/repo/myrepo/myproject (master)
$ git checkout feature-x
Switched to a new branch 'feature-x'
Branch 'feature-x' set up to track remote branch 'feature-x' from 'origin'.
  • What operating system are you using? If you are on Windows, it is case-insensitive to file names and this interfers because Windows treats two file names as referring to the same file if they only differ in casing, but git treats them as different. – Code-Apprentice Aug 11 '20 at 17:48
  • @Code-Apprentice you are exactly right, I'm on windows, thus the issue. But how to fix it. I'm using gitbash in windows machine for doing git operations. – ThrowableException Aug 11 '20 at 17:52
  • I don't know the answer. I'm googling for some related questions here on SO. So far, this is the only thing I can find: https://stackoverflow.com/questions/10523849/changing-capitalization-of-filenames-in-git, – Code-Apprentice Aug 11 '20 at 17:54
  • 1
    And here's my most fruitful search: https://duckduckgo.com/?q=git+change+capitalization+of+filenames+site%3Astackoverflow.com&ia=web. Hopefully something here will help you. – Code-Apprentice Aug 11 '20 at 17:55

2 Answers2

0

One trick to "realign" your content on disk with git's view is to temporarily rename the file :

mv ALL_UPPERCASE foo
mv foo Camel_Case

git also has a core.ignoreCase setting, the doc states :

Internal variable which enables various workarounds to enable Git to work better on filesystems that are not case sensitive, like APFS, HFS+, FAT, NTFS, etc. For example, if a directory listing finds "makefile" when Git expects "Makefile", Git will assume it is really the same file, and continue to remember it as "Makefile".

To manipulate it :

git config core.ignoreCase               # check its value
git config --global core.ignoreCase true # set it globally
LeGEC
  • 29,595
  • 2
  • 37
  • 78
  • I don't want to keep uppercase file, infact I never made any change in this file. and don't want to have my name in history by doing anything, – ThrowableException Aug 11 '20 at 18:58
0

I spend a lot of time in trying many things, but finally easiest way was to use eclipse Git Repositories view to switch to the feature-x branch and then merge the master branch into feature-x branch by using eclipse.