git status returns fatal: Not a git repository but .git exists and HEAD has proper permissions

后端 未结 8 683
无人及你
无人及你 2020-12-02 12:24

When I run git status on my repo I get fatal: Not a git repository: /my repo/.git/modules/docs

I\'ve checked and .git exists and contains HEAD with the

相关标签:
8条回答
  • 2020-12-02 12:24

    I finally sorted out that the issue was due to an issue with one of the submodules. Simply renaming the repo directory caused a conflict with that submodule. After seeing the discussion in How can I rename a git repository with submodules? I realized that cloning the repo is a better way to go instead of renaming the directory and that solved the issue with the submodule.

    0 讨论(0)
  • 2020-12-02 12:24

    In my case the problem was the .git/HEAD file didn't point anywhere, it just contained a sequence of strange characters. I copied the contents of .git/ORIG_HEAD to .git/HEAD and it worked again.

    Source

    0 讨论(0)
  • 2020-12-02 12:24

    Following @ax003d answer, you could replace all old paths (old/path) with the new path (new/path) using this command:

    find . -type f \( -name ".git" -o \( -path "*.git/modules/*" -name config \) \)  -print0 | xargs -0 sed -i -e "s#old/path#new/path#g"
    

    You might want to check what the old paths look like before replacing them:

    find . -type f \( -name ".git" -o \( -path "*.git/modules/*" -name config \) \)  -print0 | xargs -0 grep --colour "old/path"
    
    0 讨论(0)
  • 2020-12-02 12:33

    Solution :

    1) Look into the HEAD file (under .git) -> If it is corrupted (contains some random values), replace the content with this text 'ref: refs/heads/develop' (develop is the last branch I was working on)

    2) try - git status.

    3) If step 2 doesn't solve your issue, try these commands (may not work for all but worth a try)

    rm -f .git/index git reset

    4) git will give you unstaged files after reset. keep or discard as per your wish

    0 讨论(0)
  • 2020-12-02 12:38

    I solved this issue by reseting all git-submodules with

    rm -rf .git/modules
    git submodule update --init
    
    0 讨论(0)
  • 2020-12-02 12:40

    I was facing this issue with submodules as well, but after analyzing the two files

    {submodule}/.git .git/modules/submodules/{submodule}/config

    I realized that in my case this was not an issue.

    After a little research I have found that in my case I had to add the git (command : module add git) and the error disappeared.

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