最近发现有一个文件无法被restore? 我尝试添加版本库后报错 fatal:Pathspec is in submodule

原因是repo里面有另一个从远程仓库拉取的repo

引用自stackoverflow

It seems the git add context is the parent repo (“parent” means the one including the submodule), which triggers the warning.

1
2
3
cd _site
git --git-dir=.git --work-tree=. add .
git --git-dir=.git --work-tree=. commit -m "new files"

Don’t forget that, if this works, you would still have to go back to the parent repo, and git add _site, since the subrepo would have changes.

And you would have to push both

解决方法

删掉子仓库的缓存

1
2
git rm --cached directory
git add directory

OK 解决