为什么我收到“git status --porcelain failed”?

发布于 2024-11-27 02:04:10 字数 104 浏览 1 评论 0原文

突然间,当我执行 git status 操作时,我收到此 git 错误: ""git status --porcelain failed""...这是怎么回事?

All of a sudden i am getting this git error: ""git status --porcelain failed"" when i do a git status.... whats up with that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心碎的声音 2024-12-04 02:04:10

就我而言,我已将子模块移动到另一个目录,并收到该错误消息。

  1. 移动子模块后,我编辑 .gitsubmodule 以匹配子模块的当前路径。
  2. 编辑 /.gitgitdir 必须匹配 .git/modules/。它有很多../../,你可以使用ls来查看。
  3. 收到错误:-)

    致命:无法 chdir 到../:没有这样的文件或目录
    致命: git status --porcelain 在子模块中失败

  4. 编辑.git/modules//config 中失败,worktree 必须匹配子模块的当前路径。

  5. 完成。

In my case, I have moved a submodule to another directory and I got that error message.

  1. After move submodule I edit .gitsubmodule to match current path of submodule.
  2. Edit <currentPathOfSubmodule>/.git , the gitdir must match .git/modules/<pathOfSubmodule>. It has a lot of ../../, you can use ls to check.
  3. Got that error :-)

    fatal: Could not chdir to ../<someWhere>: No such file or directory
    fatal: git status --porcelain failed in submodule

  4. Edit .git/modules/<pathOfSubmodule>/config, the worktree must match current path of submodule.

  5. Done.

情未る 2024-12-04 02:04:10

在一些类似的 StackOverflow 问题中可以找到此错误消息:此处此处。谷歌搜索会显示包含此错误的邮件列表消息。没有人解释为什么会发生这种情况,所以我想我应该添加我发现的内容。

一些术语概述,来自 man git 页面:

GIT 命令

<块引用>

我们将 git 分为高级(“瓷器”)命令和低级(“管道”)命令。

从上面的帖子可以看出,当运行 git status 时,它会调用 git status --porcelain 。 man git-status 有助于告诉我们 --porcelain 标志的用途:

--瓷器

<块引用>

以易于解析的脚本格式提供输出。这与短输出类似,但仍会保留
无论用户配置如何,跨 git 版本都稳定。详情请参阅下文。

因此,您遇到的问题与 git status 调用有关,该调用默认情况下尝试将其输出格式化为易于解析的格式。

从上面的帖子中,值得注意的是此处的答案邮件列表内容,我建议,无论出于何种原因,您的 git 存储库都有变得腐败。如果您正在使用子模块,则其中一个子模块可能已损坏 - 这是相关的,因为

status 在每个填充的内部运行“git status --porcelain”
子模块以查看其是否包含更改(链接

除非明确告知不要这样做。

至于为什么你似乎有一个损坏的git存储库?我不知道。 StackOverflow 上的其他几个人提到了覆盖、移动、替换或通常摆弄其存储库中的 .git 目录。幸运的是,你有备份,对吧? ;)

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.

Some overview of terminology, from the man git page:

GIT COMMANDS

We divide git into high level ("porcelain") commands and low level ("plumbing") commands.

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:

--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.

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.

From the above posts, noticably the answers here and 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

status run "git status --porcelain" inside each populated
submodule to see if it contains changes (link)

unless explicitly told not to do so.

As to why you 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? ;)

新一帅帅 2024-12-04 02:04:10

通常,git 在项目的根目录 (.git/) 中创建一个隐藏目录。

当您在 CMS 上工作时,您可能会安装带有 .git/ 目录的模块/插件,其中包含特定模块/插件的 git 元数据

如果您不这样做想要使用 git 的子模块功能,最快的解决方案是删除除根 git 元数据目录之外的所有 .git 目录。
如果这样做,git 不会将这些模块视为项目子模块。

cd /path/to/your/project/code
find ./ | grep ".git/index"

一旦找到,删除“.git”除根目录之外的所有目录,但如果删除它,请再次初始化您的存储库

Usually, git creates a hidden directory in project's root directory (.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

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文