简体   繁体   English

Git:从……完全删除不存在的文件……从……我不知道在哪里

[英]Git : remove totally nonexistent file from… well… from I don't know where

I'm using git on Windows. 我在Windows上使用git。 I once added a file, then changed a letter in upper case, added it again with the new name. 我曾经添加一个文件,然后以大写字母更改了一个字母,然后再次以新名称添加了它。 From then, I always had the two files (once with upper case, once not). 从那时起,我始终拥有两个文件(一次使用大写,一次不使用)。

 myFile.ext
 myfile.ext

Git always interpreted it as two distinct files (as it was configures case sensitive) but it was actually the same file, so it was tracking this file two times, once under each name. Git始终将其解释为两个不同的文件(因为它配置为区分大小写),但实际上是同一文件,因此它两次跟踪该文件,每个名称下一次。

I have now deleted the upper case file from the repo with 我现在已经从仓库中删除了大写文件

git rm --cached myFile.ext

So I have now only one track of my file, and that's all good. 所以现在我的文件只有一个轨道,这一切都很好。

 myfile.ext

The problem is that if I want to make a checkout on an older commit, git says : 问题是,如果我想对旧的提交进行结帐,git说:

error: The following untracked working tree files would be overwritten by checkout: myFile.ext Please move or remove them before you can switch branches. 错误:以下未跟踪的工作树文件将被签出覆盖:myFile.ext请先移动或删除它们,然后才能切换分支。 Aborting 堕胎

However, I can't do anything with this file, because it's not in the working tree nor in the index. 但是,我对此文件无能为力,因为它既不在工作树中也不在索引中。 I tried to move the file, remove the myfile.ext file and add it again, stash, but nothing worked. 我试图移动文件,删除myfile.ext文件,然后再次添加它(隐藏),但没有任何效果。 The myFile.ext doesn't show in the git status and is not in the gitignore. myFile.ext不在git status显示,也不在gitignore中。

How can I solve this? 我该如何解决?

也许最好的方法是使用以下命令从历史记录中删除myFile.ext:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch myFile.ext' HEAD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM