如何修复被视为未跟踪的 git 跟踪文件?

How to fix a git tracked file that is treated as untracked?

症状

我有一个奇怪的问题,我想签出一个不同的分支 <branch2>,但是当我尝试时,我得到的消息是

$ git checkout <branch2>
error: The following untracked working tree files would be overwritten by checkout:
    <filename.xlsx>
Please move or remove them before you switch branches.
Aborting

但是 git ls-files<filename.xlsx> 列为跟踪文件。

解决方法

如果我执行 git checkout -f <branch2> 它会工作,并且 excel 文件的 <branch2> 版本存在且正确(类似地,如果我 rm <filename.xlsx> 然后检查我获取正确的文件。)

要返回 <branch1>,我遇到了完全相同的问题(<filename.xlsx> 已被跟踪,但结帐似乎未被跟踪)。

Testing/Troubleshooting

进一步调查这似乎与 Windows/Linux 问题有关:

最后的想法

老实说,这是一个相对容易解决的问题,而且到目前为止似乎范围仅限于 的这两个副本,但它让我很感兴趣。如果对 git 有更多了解的人对如何 diagnose/fix 这个问题的根本原因有任何想法,我将不胜感激。

额外调试

这是 git ls-files --debug 来自 <branch1>

的结果
CodeSheet.xlsx
  ctime: 1489465633:751038200
  mtime: 1489465633:751038200
  dev: 38   ino: 5432
  uid: 0    gid: 999
  size: 14752   flags: 0

这是 git ls-files --debug 来自 <branch2>

的结果
Codesheet.xlsx
  ctime: 1489467487:720851100
  mtime: 1489467487:720851100
  dev: 38   ino: 5502
  uid: 0    gid: 999
  size: 12546   flags: 0

只是猜测:这可能是 case of a file with a different case but the same name
从不区分大小写的Windows OS 的角度来看,它被跟踪了,但是从区分大小写的Debian OS 的角度来看,它 被跟踪了。

尝试:

 git config core.ignorecase true

OP Gavin mentions using "Changing capitalization of filenames in Git", with the git mv 命令。