{"thread":{"id":"31268","subject":"Having an invalid HEAD file causes git not to recognize the repository","startedAt":"2012-08-17T11:42:33Z","lastAt":"2012-08-21T08:07:22Z","messageCount":3,"participants":["Egon Elbre","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"197176","messageId":"CANtNKfp+9HpvWkAO0vrm84oMiJNvjFg9T-UtNQko+ABHhEWj6w@mail.gmail.com","threadId":"31268","inReplyTo":null,"subject":"Having an invalid HEAD file causes git not to recognize the repository","fromName":"Egon Elbre","fromEmail":"egonelbre@gmail.com","sentAt":"2012-08-17T11:42:33Z","receivedAt":"2012-08-17T11:42:33Z","isPatch":false,"sender":{"key":"egonelbre@gmail.com","avatar":null},"body":"Having an invalid HEAD file causes git not to recognize the repository\nand will cause an invalid message \"fatal: Not a git repository (or any\nof the parent directories): .git\" although there is a .git folder and\neverything seems okay in it. Solution was just to change HEAD to a\nvalid ref/hash.\n\nI ran into this problem when I had a BSOD during a rebase (ignore that\nI'm having to use Windows). This meant that only half of the hash got\nwritten into HEAD and all git commands I tried failed.\n\nNot sure whether it's useful to add a better message for this case,\nbut at least if somebody stumbles on it again, maybe they can find\nthis text.\n\n+ egon\n"},{"id":"197514","messageId":"20120821072403.GD3238@sigill.intra.peff.net","threadId":"31268","inReplyTo":"CANtNKfp+9HpvWkAO0vrm84oMiJNvjFg9T-UtNQko+ABHhEWj6w@mail.gmail.com","subject":"Re: Having an invalid HEAD file causes git not to recognize the repository","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-08-21T07:24:03Z","receivedAt":"2012-08-21T07:24:03Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Aug 17, 2012 at 02:42:33PM +0300, Egon Elbre wrote:\n\n> Having an invalid HEAD file causes git not to recognize the repository\n> and will cause an invalid message \"fatal: Not a git repository (or any\n> of the parent directories): .git\" although there is a .git folder and\n> everything seems okay in it. Solution was just to change HEAD to a\n> valid ref/hash.\n\nRight. When we search for a .git directory, we do a few sanity checks on\neach candidate, like whether it has a properly-formatted HEAD, and\nwhether it has \"objects\" and \"refs\" directories. We have to balance\nthese heuristics to avoid false negatives (like yours, when the\ndirectory was meant to be a repository but looked bogus) with false\npositives (when we accidentally treat some random directory like a git\nrepository).\n\nSince you don't have a working repository, the best we could do is say\n\"well, this looks like a repository, but it's broken, so I kept\nlooking\". I think the best approach would probably be to have a new\nGIT_TRACE_GITDIR environment variable to help debug git-dir lookup\n(i.e., to print out details of the search as it happens).\n\n> I ran into this problem when I had a BSOD during a rebase (ignore that\n> I'm having to use Windows). This meant that only half of the hash got\n> written into HEAD and all git commands I tried failed.\n\nThat generally shouldn't happen, as we write new ref content to a\ntemporary file and then rename it into place atomically. I wonder if\nthere is a problem with the atomicity there (we do not fsync after\nclose, which some filesystems might want), or if it was simply\nfilesystem corruption related to your BSOD.\n\n-Peff\n"},{"id":"197517","messageId":"CANtNKfr1SMvpOrjowk+ewk2aiwiZCUzRwuw4wHFjQ3N-BmGikg@mail.gmail.com","threadId":"31268","inReplyTo":"20120821072403.GD3238@sigill.intra.peff.net","subject":"Re: Having an invalid HEAD file causes git not to recognize the repository","fromName":"Egon Elbre","fromEmail":"egonelbre@gmail.com","sentAt":"2012-08-21T08:07:22Z","receivedAt":"2012-08-21T08:07:22Z","isPatch":false,"sender":{"key":"egonelbre@gmail.com","avatar":null},"body":"On Tue, Aug 21, 2012 at 10:24 AM, Jeff King <peff@peff.net> wrote:\n>\n>> I ran into this problem when I had a BSOD during a rebase (ignore that\n>> I'm having to use Windows). This meant that only half of the hash got\n>> written into HEAD and all git commands I tried failed.\n>\n> That generally shouldn't happen, as we write new ref content to a\n> temporary file and then rename it into place atomically. I wonder if\n> there is a problem with the atomicity there (we do not fsync after\n> close, which some filesystems might want), or if it was simply\n> filesystem corruption related to your BSOD.\n>\n\nIt's a truecrypt drive and I had to run diskcheck on the drive\n(because of bad unmounting). In essence the file could have been\ninvalid and just restored it to some invalid usable state. Also it\nmight be truecrypt atomicity problem.\n\n+egon\n"}]}