Search code examples
gitgit-commitdrive

I've updated Git and 'lost my Head', so now I can't commit


I recently downloaded git 2.19.0.windows.1. In the previous versions of git, I could git clone and git commit from/to both my local drive and my H drive. Now with this version of git, I can only git clone and commit on my local drive but not on my H drive. When I commit on my H drive I get the following error:

 fatal: cannot update the ref 'HEAD': unable to append to '.git/logs/HEAD': Bad file descriptor

I have tried to find my head using the following code:

 $ echo ref: refs/head/master >.git/HEAD

This does not work, I don't know what the next move is.


Solution

  • Check first what git status and git config -l when done in your repository on H:\: when in doubt (in an IDE), fall back to the command line.

    As mentioned here, a branch yet to be born generally means an new empty repo where at least one commit is needed.

    That or, as illustrated there:

    • you have an environment variable GIT_WORK_TREE or GIT_DIR set referencing another repo
    • your .git/refs/HEAD does not reference an existing branch (you can open it and see its content)