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...
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.
In case it helps anyone else, I just encountered the same issue and found that running git init
in the project root fixed it.
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 init
in the main project's root. Fixed the problem for me.
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.
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.
In my case after moving moduleA/mySubmodule
to moduleB/mySubmodule
using git mv moduleA moduleB
with git 2.12.2, I ran into the follwoing 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 follwing (Maybe in not this order)
- Manually update
.gitmodules
entry tomoduleB
- Enter
.git/modules
and rename old module folder - Enter
moduleB
and delete submodules folder - Run
git submodule sync
andgit submodule update
After that, I could run git status
again without problems.
I don't have any .git folders in my repo, but anytime I copy my new files into my folder to update my app, I am still getting index corrupt porcelain failed errors. I don't understand how updating files would corrupt this or how to fix it. Anyone have further insight on this?
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
.git
is a file in submodules and points to a directory located in your root .git
directory.
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 .git
file to change the gitdir path to a relative path.
Git version: 2.7.4
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
.
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
来源:https://stackoverflow.com/questions/5456683/why-do-i-get-fatal-git-status-porcelain-failed