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...
14 Answers
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.
5 Comments
.git folders from vendor folder of only the problematic-ones dependencies. It has happened to me with @dev dependency after that target repo got through some rebasing.git pull in the submodule.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.
1 Comment
git submodule init && git submodule update as well.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.
Comments
In case it helps anyone else, I just encountered the same issue and found that running git init in the project root fixed it.
1 Comment
git init in the submodule and indeed the problem went away. Thanks!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.
Comments
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)
- Manually update
.gitmodulesentry tomoduleB - Enter
.git/modulesand rename old module folder - Enter
moduleBand delete submodules folder - Run
git submodule syncandgit submodule update
After that, I could run git status again without problems.
Comments
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
Comments
.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
1 Comment
I managed to solve the issue as follows:
Lets assume subfolder is the submodule where I was facing the issue, I moved/deleted the folder then sync and then update...
mv AD_Soft/subfolder AD_Soft/subfolder2 git submodule sync --recursive AD_Soft/subfolder/ git submodule update --recursive AD_Soft/subfolder This solves the issue for me..
Comments
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?
4 Comments
npm's CoffeeScript modules, specifically the grunt ones, even if I haven't created any cake plugins myself?Delete the .git folder from the module. Please keep the backup of that folder if you want to use it future.
1 Comment
.git was created in my case by running accidentally git pull in submodule.)I also faced the same error, with a problem slightly similar to the one of this solution: I also have a Git submodule in my main repo and, while wanting to change its directory name, I typep mv old_name new_name by mistake instead of git mv old_name new_name, so that all the links would automatically be maintained correctly by Git itself.
Rolling back to the old name and then typing the correct command (with git first, then) saved the problem!
By the way, I got the intuition of the incorrect link from this answer, actually (plus involving my short-term brain memory about what commands I had typed few moments before). Thanks!