25

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

Doz
  • 7,009
  • 12
  • 61
  • 69
  • If you moved files around and have multiple .git files in the repo it can cause this problem, ensure there is only one .git file in the root directory of the archive – Kmeixner Sep 05 '13 at 17:22

3 Answers3

47

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.

bryanbraun
  • 3,025
  • 2
  • 26
  • 38
cakyus
  • 776
  • 1
  • 6
  • 13
15

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? ;)

Community
  • 1
  • 1
simont
  • 68,704
  • 18
  • 117
  • 136
  • Thanks it was a while ago and i just restored from backup rather than do it your way but perhaps next time if i an unfortunate to get that issue again... – Doz Feb 14 '12 at 00:06
  • 1
    My submodule has an absolute path as the value for `gitdir`; doing a `git mv` caused this path to be invalid. It looks like git isn't smart enough to update submodule paths when moving files, even when using its own ecosystem commands. – Dagrooms Jun 16 '17 at 14:09
  • Mine was saying `fatal: cannot chdir to '../../../../Modules/my_include': No such file or directory` so I created Modules/my_include, that made that error go away – pdcoxhead Aug 01 '19 at 02:46
1

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

yilmi
  • 162
  • 5