Git提交的文件,但是不在仓库中 [英] Git committed file but it's not in the repo
问题描述
我上演了一个文件并将其提交到本地git存储库,这似乎正常工作.
I staged and committed a file to a local git repository and this appeared to work correctly.
但是,在检查存储库时,它似乎不存在.摘自我的命令会议:
However on examining the repository it doesn't appear to be present. Excerpt from my command session:
D:\myproject>git log -1 --stat
...
myfile.h | 27 +-
...
30 files changed, 18501 insertions(+), 15303 deletions(-)
D:\myproject>git ls-files myfile.h
D:\myproject>
该文件应该已经存在很长时间了,多次提交.
显然,我担心其他文件的提交也可能会默默地失败.
This file should have been present in the repository for a long time, over multiple commits.
Obviously I am worried that commit may also have silently failed for other files.
如何确保所有更改都正确提交?
How can I ensure my changes are all committed correctly?
推荐答案
该文件原来在存储库中存在,但是路径具有不同的大小写.例如,
The file turned out to be present in the repository but the path had different case. e.g.,
存储库:ParentFolder/myfile.h
工作目录:parentfolder/myfile.h
尽管Windows将这些路径视为相同的路径,但即使ignoreCase
选项设置为true(ignoreCase
显然仅影响暂存区域,但不影响git ls-files
,git diff
等),git也不认为.
While Windows sees these as the same path, git doesn't, even with the ignoreCase
option set to true (ignoreCase
apparently only affects the staging area not git ls-files
, git diff
etc).
解决方法是编写一个脚本,将find
(gnu/msys查找为Windows查找!)与git ls-files
的输出进行比较,以查找以此方式受影响的所有文件.受影响的文件是存储库中存在的文件,它们在工作树中具有不区分大小写的匹配,但不区分大小写.然后,对于每个副本,删除并重新添加到Git中,请注意不要删除本地副本:
The fix was to write a script comparing the output of find
(gnu/msys find not Windows find!) to git ls-files
to find all files affected in this way. The affected files are those present in the repo which have a case insensitive, but not case sensitive match in the working tree. Then for each one, delete and re-add in Git, being careful not to delete the local copy:
git rm --cached ParentFolder/myfile.h
git add parentfolder/myfile.h
然后提交.
这篇关于Git提交的文件,但是不在仓库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!