Git 尽管文件存在,但无法在远程中找到文件

Git cannot find file in remote despite file being there

我有一个文件 project/data/data.csv,其中 project/ 是父项目,data/ 是子模块。在 project/data/ 我 运行 git checkout origin/master data.csv

git 回复:

error: pathspec 'data.csv' did not match any file(s) known to git.

然而,当我在 gitlab 上学习时,文件就在那里。

我尝试过 git 重置、git 获取和 git 拉取,其中 none 已经解决了问题。

在 git 变得疯狂之前发生的事情是我得到了一个损坏的树对象。要解决此问题,我必须删除所有此类对象,然后执行 git 获取和 git 拉取。

这导致数据子模块报告一个脏对象,我通过删除 .git 文件并执行 git 拉动来修复此问题。

之后我似乎可以毫无问题地拉动和推动,所以我不确定它是否相关。

关于如何让 git 再次跟踪文件的任何建议?

要跟踪该文件,试试这个:

git add data.csv

也许试试

git submodule update --rebase --remote

如果您已经损坏并最终删除了 .git 您已经尝试过硬重置(假设您已经尝试过 git reset origin/master 并且不担心丢失任何文件。如果那是案例尝试 git clone <repo> 这应该用正确的文件重新初始化你的 repo