为什么我得到“致命的:git status --porcelain failed”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5456683/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:27:56  来源:igfitidea点击:

Why do I get "fatal: git status --porcelain failed"?

gitversioning

提问by Ahmed Nuaman

This is a huge pain in the bum. I've got this a few times before and I don't understand why. 5 mins ago the repo was fine and working, I move some files around (which is all cool and all) and git poops its pants. Any idea why this happens? How can I fix it apart from cloning the repo, moving the files, etc...

这是流浪汉的巨大痛苦。我以前遇到过几次,我不明白为什么。5 分钟前,repo 很好并且工作正常,我移动了一些文件(这一切都很酷)并且 git 拉裤子。知道为什么会这样吗?除了克隆存储库,移动文件等,我该如何修复它...

回答by Ahmed Nuaman

Oh dear I'm such a fail. It looks like the problem stems from Flash Builder copying over other .git repos into sub folders. The answer is to remove all .git folders that aren't the repo's one.

哦,天哪,我真是个失败者。看起来问题源于 Flash Builder 将其他 .git 存储库复制到子文件夹中。答案是删除所有不是 repo 的 .git 文件夹。

回答by Michael Thiel

I ran into this error because of a corrupted/not properly initialized submodule (with its own .git subfolder). I temporarily deleted the submodules folder and used git initin the main project's root. Fixed the problem for me.

由于子模块损坏/未正确初始化(带有自己的 .git 子文件夹),我遇到了这个错误。我暂时删除了子模块文件夹并git init在主项目的根目录中使用。为我解决了问题。

回答by Tom

I know this is an old thread, but I just had the same problem and ended up solving in a different way. The git initdidin't work for me. Posting here, in case it's useful to anyone else.

我知道这是一个旧线程,但我遇到了同样的问题,最终以不同的方式解决。没有git init对我来说有效。在这里发布,以防对其他人有用。

My repository has two submodules. After rebasing I started getting the error fatal: git status --porcelain failed.

我的存储库有两个子模块。重新定位后,我开始收到致命错误: git status --porcelain failed

The solution was to verify the property worktreein every submodule configfile - e.g. <repository-checkout>/.git/modules/<submodule-name>/config.

解决方案是验证worktree每个子模块config文件中的属性- 例如<repository-checkout>/.git/modules/<submodule-name>/config.

I had one invalid path for the worktreeproperty. It was linking to an unexisting folder that was changed and merged to master- probably due an error resolving conflicts.

我有一个无效的worktree属性路径。它链接到一个不存在的文件夹,该文件夹已更改并合并到master-可能是由于解决冲突时出错。

回答by Jordan Running

In case it helps anyone else, I just encountered the same issue and found that running git initin the project root fixed it.

如果它对其他人有帮助,我刚刚遇到了同样的问题,并发现在git init项目根目录中运行修复了它。

回答by Web_Designer

I had the same issue. Running git statusin my root project's directory produced the following error:

我遇到过同样的问题。git status在我的根项目目录中运行产生以下错误:

fatal: This operation must be run in a work tree
fatal: 'git status --porcelain' failed in submodule js/object-subscribe

Running git statusin the affected submodule (js/object-subscribe) would produce this error:

git status在受影响的子模块 ( js/object-subscribe) 中运行会产生以下错误:

fatal: This operation must be run in a work tree

Running git initin that submodule's folder did it for me.

git init在该子模块的文件夹中运行为我做到了。

回答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”除根目录之外的所有目录,但如果您删除它,请再次初始化您的回购

回答by Checo R

In my case after moving moduleA/mySubmoduleto moduleB/mySubmoduleusing git mv moduleA moduleBwith git 2.12.2, I ran into the follwoing error:

在运动后,我的情况下moduleA/mySubmodule,以 moduleB/mySubmodule使用git mv moduleA moduleBGit的2.12.2,我跑进follwoing错误:

$ git status
fatal: Could not chdir to '[../]moduleA/mySubmodule': No such file or directory
fatal: 'git status --porcelain' failed in submodule mySubmodule
fatal: 'git status --porcelain' failed in submodule moduleB

Then I did the follwing (Maybe in not this order)

然后我做了以下(也许不是这个顺序)

  1. Manually update .gitmodulesentry to moduleB
  2. Enter .git/modulesand rename old module folder
  3. Enter moduleBand delete submodules folder
  4. Run git submodule syncand git submodule update
  1. 手动更新.gitmodules条目moduleB
  2. 输入.git/modules并重命名旧模块文件夹
  3. 进入moduleB和删除子模块文件夹
  4. 运行git submodule syncgit submodule update

After that, I could run git statusagain without problems.

在那之后,我可以git status毫无问题地再次运行。

回答by Zythos

For me it was different, nor git initsolved the issue nor the worktreewas wrong. The error that I had was

对我来说,这是不同的,既没有git init解决问题,也没有worktree错误。我的错误是

fatal: unable to create threaded lstat
fatal: 'git status --porcelain=2' failed in submodule ext/hdf5

The solution for me was git gc.

我的解决方案是git gc.

回答by Bang Andre

git remote -v
#now run the same commands 
git remote add origin remote-repository-url.git
git push origin master

// It's work very well

// 它工作得很好

回答by Shubham Chaudhary

.gitis a file in submodules and points to a directory located in your root .gitdirectory.

.git是子模块中的文件,指向位于根.git目录中的目录。

In my case, I was mounting a git directory in docker and checking status there. The .git file of this submodule contained an absolute path which was invalid in docker. I edited this .gitfile to change the gitdir path to a relative path.

就我而言,我在 docker 中安装了一个 git 目录并在那里检查状态。此子模块的 .git 文件包含在 docker 中无效的绝对路径。我编辑了这个.git文件以将 gitdir 路径更改为相对路径

Git version: 2.7.4

Git 版本:2.7.4