Weird issues with Git version control

Answered

Hey, I recently updated from PHPstorm 9 to the latest one and it seems to have messed with my local Git repo.
I'm really noob with Git so I have no clue what's actually happening here, but it seems to me like the .git repo got corrupted somehow?

I get the following error in the console when I try to commit changes to 41 files:

0 files committed, 41 files failed to commit: Created API system pathspec 'ThisIsANewDeletedFile.php' did not match any files
On branch master
Changes not staged for commit:
modified: xxxxxxxxxxxxxx.php
modified: xxxxxxxxxxxxxx.php
modified: xxxxxxxxxxxxxx.php
modified: xxxxxxxxxxxxxx.php
modified: xxxxxxxxxxxxxx.php
deleted: xxxxxxxxxxxxxx.php
modified: xxxxxxxxxxxxxx.php
modified: xxxxxxxxxxxxxx.php
Untracked files:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
no changes added to commit

There are items listed under Untracked files that I would like to add to the version control but the Git->Add option is greyed out. If I click on commit, the Commit Changes window opens up but the Commit button is greyed out and there's a red text "Warning: not all local changes may be shown due to an error: Not a git repository (or any of the parent directories): .git.

The .git directory does exist and none of the files in it are empty or seem corrupted to my eye, unlike one time when the index file was emptied. Now it might be corrupted in a different way.

Does anyone have a clue how I could fix this?

13 comments

First of all check that you have correct VCS roots registered at File | Settings | Version Control. 

Then try committing from Terminal & check if errors would be any different.

 

0

Thanks for the reply.
Anything I try to do in the terminal results in fatal: Not a git repository (or any of the parent directories): .git.

My project's VCS settings have not changed and the roots are still listed in the version control menu.

0

Are git roots listed in Version Control Settings matching the directory you're running git commands in? See https://stackoverflow.com/a/23975989/8020009

 

0

Hey, thanks for the help so far. My PC blew on Thursday and I couldn't get back sooner.

Yes, I have the .git directory in the path C:\xxx\xxx\.git. C:\xxx\xxx is also my project root and it's listed in the Version Control settings menu along with 2 subfolders. The terminal starts off in this path as well.

All settings seem as they should be and I don't see any difference to when everything worked.

 

0

So if you open terminal, then do cd C:\xxx\xxx\, then git status - it would return fatal: Not a git repository?

0

That's exactly right. Also the Local changes and Log tabs seem to work fine, which is odd, although I don't know if that data is stored by git or PhpStorm. Also I just reinstalled Windows and git so the git installation isn't to blame.

C:\xxx\xxx>git status
fatal: not a git repository (or any of the parent directories): .git

C:\xxx\xxx>dir .git
Volume in drive C has no label.
Volume Serial Number is XXXXXXXXXXXXX

Directory of C:\xxx\xxx\.git

18/03/2019 14.07 <DIR> .
18/03/2019 14.07 <DIR> ..
24/09/2017 16.04 130 config
24/09/2017 16.04 73 description
24/09/2017 16.04 23 HEAD
18/03/2019 14.07 <DIR> hooks
15/09/2018 17.55 1 702 416 index
18/03/2019 14.07 <DIR> info
18/03/2019 14.07 <DIR> objects
4 File(s) 1 702 642 bytes
5 Dir(s) 1 757 282 148 352 bytes free

0

I tried replacing the 3 .git folders with backups from a month ago (after which I had made a successful commit) but that didn't change anything either. I also realized the Local changes does not work, contrary to what I said earlier. It always shows the same 40 files and new files and changes aren't added to it and there's an error in the bottom: "Error updating changes: not a git repository (or any of the parent directories): .git"

I've uploaded the idea.log starting from the last phpstorm restart hoping it could provide some insight. I renamed some of the folder references but made sure the meaning doesn't change. https://www.dropbox.com/s/ue6tny5a20isi1x/idea%20truncated.log?dl=0

0

Do you mind if we continue checking this in a support ticket? 

I'm afraid we would need to see paths without obfuscation.

0

That would be great. What do I need to do?

0

I've created a ticket for you.

0

Git repository is corrupted indeed - it is missing the refs folder which stores information about branches. Re-cloning or restoring the refs folder from a working clone should help.

0

Thanks.

Turns out the repo had possibly not been used for over a year and maybe it being corrupted didn't affect older versions of PHPstorm.

I simply removed the repo from my version control and renamed the .git directory (so that it wouldn't nag me that there's an unregistered repo), leaving only my 2 other repos and now it seems to work. I didn't need that repo anyway but I never realized.

0

All IntelliJ IDEs handle all repositories in the project as a whole, considering all repositories as important part of a project. So if some of the mapped repositories faile - Local changes report errors and fail as well.

If you don't need a repository - unmapping it, or removing the .git folder there is the correct way to solve the issue.

1

Please sign in to leave a comment.