Git:致命:Pathspec 在子模块中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24472596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: fatal: Pathspec is in submodule
提问by jmite
I'm trying to get TravisCI to automatically deploy my Hakyll static site, according to this guide.
根据本指南,我正在尝试让 TravisCI 自动部署我的 Hakyll 静态站点。
Here's how my repo is set up. I have my source branch, which contains my hakyll and markdown files. It builds the html into the _site
directory, which is set up as a submodule, linked to my master
branch.
这是我的回购的设置方式。我有我的源分支,其中包含我的 hakyll 和 markdown 文件。它将 html 构建到_site
目录中,该目录设置为子模块,链接到我的master
分支。
I build the site without problem, then cd
into the _site directory. However, when I try to git add ./*
the newly generated HTML files, I get the following error:
我建立网站没有问题,然后cd
进入 _site 目录。但是,当我尝试git add ./*
使用新生成的 HTML 文件时,出现以下错误:
fatal: Pathspec './about.html' is in submodule '_site'
When I try git add --all
, I get this error:
当我尝试时git add --all
,我收到此错误:
git: pathspec.c:317: prefix_pathspec: Assertion `item->nowildcard_len <= item->len && item->prefix <= item->len' failed.
/home/travis/build.sh: line 245: 1566 Aborted git add --all
What is causing this, and how can I avoid this?
是什么导致了这种情况,我该如何避免这种情况?
You can view the repository here.
您可以在此处查看存储库。
回答by kqw
Removing the directory from git and adding it again worked for me:
从 git 中删除目录并再次添加它对我有用:
git rm --cached directory
git add directory
This works if you purposefully removed the .git
directory because you wanted to add directory
to your main git project. In my specific case, I had git cloned an extension and ran git add .
without thinking too much. Git decided to create a submodule, which I didn't like. So I removed directory/.git
and ran into Git: fatal: Pathspec is in submodule
. I couldn't find out how to remove the submodule stuff. Fixed with the two lines above.
如果您有意删除.git
目录,因为您想添加directory
到您的主 git 项目,这将起作用。在我的特定情况下,我让 git 克隆了一个扩展,并git add .
没有考虑太多就跑了。Git 决定创建一个我不喜欢的子模块。所以我删除directory/.git
并运行到Git: fatal: Pathspec is in submodule
. 我不知道如何删除子模块的东西。用上面的两行固定。
回答by VonC
It seems the git add
context is the parent repo ("parent" means the one including the submodule), which triggers the warning.
git add
上下文似乎是触发警告的父回购(“父”表示包括子模块的那个)。
Try and change its context with:
尝试使用以下方法更改其上下文:
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.
不要忘记,如果这有效,您仍然需要返回父存储库,并且git add _site
,因为子存储库会发生变化。
And you would have to push both.
你必须同时推动两者。
Update January 2017 (2+ years later)
2017 年 1 月更新(2 年后)
With Git 2.12, you won't see that prefix_pathspec: Assertion
anymore.
使用 Git 2.12,您将不再看到它prefix_pathspec: Assertion
。
See commit 2d81c48(09 Jan 2017) by Stefan Beller (stefanbeller
).
Helped-by: Jeff King (peff
), and Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
--in commit 00880a1, 18 Jan 2017)
请参阅Stefan Beller ( ) 的commit 2d81c48(09 Jan 2017 )。
帮助者:Jeff King ( )和Junio C Hamano ( )。(由Junio C Hamano合并-- --在commit 00880a1,2017 年 1 月 18 日)stefanbeller
peff
gitster
gitster
pathspec
: give better message for submodule relatedpathspec
errorRunning "
git add a/b
" when "a
" is a submodule correctly errored out, but without a meaningful error message.
pathspec
:为子模块相关pathspec
错误提供更好的信息
git add a/b
当“a
”是一个正确错误的子模块时运行“ ” ,但没有有意义的错误消息。
回答by jmite
It seems my problem is that I was accidentally deleting the .git
folder of the submodule.
看来我的问题是我不小心删除.git
了子模块的文件夹。
回答by kenorb
It sounds like you're operating on non-initialized submodules (they're basically missing .git
directories), therefore you should initialize them first and update:
听起来您正在对未初始化的子模块进行操作(它们基本上缺少.git
目录),因此您应该先初始化它们并更新:
git submodule init
git submodule update
Otherwise if you don't need this submodule anymore, remove it by:
否则,如果您不再需要此子模块,请通过以下方式将其删除:
git submodule deinit _site
or:
或者:
git rm -f --cached _site
and add it again:
并再次添加:
git add _site
Check your current outstanding submodules by: git submodule status
.
通过检查您当前突出的子模块:git submodule status
。
See also: Why is git erroring with 'Assertion failed' on git add .?
回答by John Smit Conor
100% fix for this problem, even if you have more than one submodule directory inside the project:
100% 修复这个问题,即使你在项目中有多个子模块目录:
> git submodule foreach --recursive deinit -f --all -- <relative path>
> git add --all -f