gitgit-untracked

Git is considering a checked in file as untracked, upon rename


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,

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'.

Solution

  • 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.