为什么我会收到“git status --porcelain failed”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6888759/
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
Why am i getting "git status --porcelain failed"?
提问by Doz
All of a sudden i am getting this git error: ""git status --porcelain failed""when i do a git status.... whats up with that?
突然间,当我执行 git status 时,我收到了这个 git 错误:“"git status --porcelain failed"”......这是怎么回事?
采纳答案by simont
This error message is found in some similar StackOverflow questions: here, here. Googling brings up a mailing list message with this error. Nobody has given an explanation why it occurs, so I thought I'd add what I've found.
在一些类似的 StackOverflow 问题中可以找到此错误消息:here,here。谷歌搜索会出现一条带有此错误的邮件列表消息。没有人解释为什么会发生这种情况,所以我想我会添加我发现的内容。
Some overview of terminology, from the man git
page:
一些术语概述,来自man git
页面:
GIT COMMANDS
We divide git into high level ("porcelain") commands and low level ("plumbing") commands.
git 命令
我们将 git 分为高级(“瓷器”)命令和低级(“管道”)命令。
From the above posts, it would appear that, when git status
is run, it calls git status --porcelain
. man git-status
helpfully informs us what the --porcelain
flag is for:
从上面的帖子中可以看出,在git status
运行时,它会调用git status --porcelain
. man git-status
有用地告诉我们该--porcelain
标志的用途:
--porcelain
Give the output in an easy-to-parse format for scripts. This is similar to the short output, but will remain stable across git versions and regardless of user configuration. See below for details.
- 瓷
以易于解析的格式为脚本提供输出。这类似于短输出,但无论用户配置如何,在 git 版本中都将保持稳定。详情请见下文。
So the issue you have is related to the git status
call, which is by default trying to format its output into something easy to parse.
因此,您遇到的问题与git status
调用有关,默认情况下,调用会尝试将其输出格式化为易于解析的内容。
From the above posts, noticably the answers hereand the mailing list contentets, I would suggest that, for whatever reason, your git repository has become corrupted. If you're using submodules, it's possible one of those has become corrupted - this is relevant because
从上面的帖子,特别是这里的答案和邮件列表 contentets,我建议无论出于何种原因,您的 git 存储库已损坏。如果您正在使用子模块,则其中一个可能已损坏 - 这是相关的,因为
status run "git status --porcelain" inside each populated submodule to see if it contains changes (link)
status 在每个填充的子模块中运行“git status --porcelain”以查看它是否包含更改(链接)
unless explicitly told not to do so.
除非明确告知不要这样做。
As to whyyou seem to have a corrupted git repository? I don't know. Several other people on StackOverflow have mentioned overwriting, moving, replacing, or generally fiddling with .git
directories in their repositories. Luckily, you have a backup, though, right? ;)
至于为什么你似乎有一个损坏的 git 存储库?我不知道。StackOverflow 上的其他几个人提到了覆盖、移动、替换或通常摆弄.git
他们存储库中的目录。幸运的是,您有备份,对吗?;)
回答by cakyus
In my case, I have moved a submodule to another directory and I got that error message.
就我而言,我已将一个子模块移动到另一个目录,并且收到了该错误消息。
- After move submodule I edit
.gitsubmodule
to match current path of submodule. - Edit
<currentPathOfSubmodule>/.git
, thegitdir
must match.git/modules/<pathOfSubmodule>
. It has a lot of../../
, you can usels
to check. Got that error :-)
fatal: Could not chdir to
../<someWhere>
: No such file or directory
fatal:git status --porcelain
failed in submoduleEdit
.git/modules/<pathOfSubmodule>/config
, theworktree
must match current path of submodule.Done.
- 移动子模块后,我编辑
.gitsubmodule
以匹配子模块的当前路径。 - 编辑
<currentPathOfSubmodule>/.git
,gitdir
必须匹配.git/modules/<pathOfSubmodule>
。它有很多../../
,你可以ls
用来检查。 得到那个错误:-)
致命:无法 chdir 到
../<someWhere>
:没有这样的文件或目录
致命:git status --porcelain
在子模块中失败Edit
.git/modules/<pathOfSubmodule>/config
,worktree
必须匹配子模块的当前路径。完毕。
回答by yilmi
Usually, git creates a hidden directory in project's root directory (.git/)
通常,git会在项目的根目录(.git/)中创建一个隐藏目录
When you're working on a CMS, its possible you install modules/plugins carrying .git/ directory with git's metadata for the specific module/plugin
当您在 CMS 上工作时,您可能会安装带有 .git/ 目录的模块/插件,其中包含特定模块/插件的 git 元数据
If you do not want to use git's submodules feature, quickest solution delete all .git directories except root git metadata directory. If you do so, git will not consider those modules as project submodules.
如果您不想使用 git 的子模块功能,最快的解决方案是删除除根 git 元数据目录之外的所有 .git 目录。如果这样做,git 不会将这些模块视为项目子模块。
cd /path/to/your/project/code
find ./ | grep ".git/index"
Once located delete ".git" all directories except the root one, but if you deleted it initialize your repo again
一旦找到删除“.git”除根目录之外的所有目录,但如果您删除它,请再次初始化您的回购