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

前端 未结 13 1877
星月不相逢
星月不相逢 2020-12-09 07:39

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 a

相关标签:
13条回答
  • 2020-12-09 08:21

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

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

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

    fatal: This operation must be run in a work tree
    

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

    0 讨论(0)
  • 2020-12-09 08:21

    Delete the .git folder from the module. Please keep the backup of that folder if you want to use it future.

    0 讨论(0)
  • 2020-12-09 08:25

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

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

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

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

    0 讨论(0)
  • 2020-12-09 08:25

    For me it was different, nor git init solved the issue nor the worktree was wrong. The error that I had was

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

    The solution for me was git gc.

    0 讨论(0)
  • 2020-12-09 08:27

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

    0 讨论(0)
  • 2020-12-09 08:27

    In my case after moving moduleA/mySubmodule to moduleB/mySubmodule using git mv moduleA moduleB with git 2.12.2, I ran into the following error:

    $ 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 following (Maybe not in this order)

    1. Manually update .gitmodules entry to moduleB
    2. Enter .git/modules and rename old module folder
    3. Enter moduleB and delete submodules folder
    4. Run git submodule sync and git submodule update

    After that, I could run git status again without problems.

    0 讨论(0)
提交回复
热议问题