title: Recovering Git repo from file "is not a GIT packfile"
body: <p>I have no idea what could be wrong with this computer, but I shut it down, half an hour later I start it up, do <code>git status -uno</code>, and it tells me one of the submodules "is not" something. Then I realize the <code>.git/submodules</code> dir is empty. Then I copy those from elsewhere, <code>git status -uno</code> gave me a bunch of unrelated changes (one .txt file became suddenly a directory ?). Then I try <code>git pull</code>, it gives me a ton of</p>
  
  <pre><code>error: file .git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack is not a GIT packfile
  warning: packfile .git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack cannot be accessed
  </code></pre>
  
  <p>... but the pull completed. Now I still have the unrelated changes in status, but then I try <code>git fsck --full</code>, I get:</p>
  
  <pre><code>$ git fsck --full
  Checking object directories: 100% (256/256), done.
  error: file .git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack is not a GIT packfile
  fatal: packfile .git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack cannot be accessed
  </code></pre>
  
  <p>Is there any way I could restore this repo, such that the present unchecked files are still there? (I have some logs that I still need, but shouldn't be checked in, in the larger scope of things). I would have hoped <code>git pull</code> would restore it, but apparently it doesn't... </p>
  
  <hr>
  
  <p>EDIT, found these packfiles on another local copy of the same repo, but now this happens:</p>
  
  <pre><code>cp -av /second/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38* /first/myrepo/.git/objects/pack/
  ‘/second/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.idx’ -&gt; ‘/first/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.idx’
  cp: cannot create regular file ‘/first/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.idx’: Permission denied
  ‘/second/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack’ -&gt; ‘/first/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack’
  cp: cannot create regular file ‘/first/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack’: Permission denied
  </code></pre>
  
  <p>But why do I get permission denied, I am the owner of those files?</p>
  
  <pre><code>$ ls -la /first/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38*
  -r--r--r-- 1 MYUSER MYUSER    214656 Aug 18 11:05 /first/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.idx
  -r--r--r-- 1 MYUSER MYUSER 111503621 Aug 18 11:05 /first/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack
  </code></pre>
  
  <p>Just having the permissions <code>rrr</code> shouldn't make a difference, right ?! (although it seems they have been copied, the file sizes seem right)...</p>