Git 在重命名时将签入的文件视为未跟踪

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

在我的 git 项目中,开发人员之一 昨天将文件名从 全部大写更改为 CamelCase。在他的功能 b运行ch 中并合并到 master

我拉到了远程高手。现在,在任何本地 git 操作期间,git 将大写(旧)文件的消息显示为未跟踪。 虽然文件在提到的文件夹中处于提交状态,但我从未在本地接触过它。

我试过了,

但是现在,如果我在 feature-x b运行ch 中进行任何操作,我会再次收到此错误。

我可以像上面那样通过手动删除来解决这个问题。 但是想知道有没有正确的方法来处理这种情况。

以下是我 运行 的所有确切命令,并重命名为 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'.

根据 git 的观点“重新对齐”磁盘上的内容的一个技巧是临时重命名文件:

mv ALL_UPPERCASE foo
mv foo Camel_Case

git 也有一个 core.ignoreCase 设置,文档指出:

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

要操纵它:

git config core.ignoreCase               # check its value
git config --global core.ignoreCase true # set it globally

我花了很多时间尝试很多事情,但最后最简单的方法是使用 eclipse Git Repositories 视图切换到 feature-x 分支然后使用 eclipse.

将 master 分支合并到 feature-x 分支