简体   繁体   中英

Recovering Git repo from file “is not a GIT packfile”

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 git status -uno , and it tells me one of the submodules "is not" something. Then I realize the .git/submodules dir is empty. Then I copy those from elsewhere, git status -uno gave me a bunch of unrelated changes (one .txt file became suddenly a directory ?). Then I try git pull , it gives me a ton of

error: file .git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack is not a GIT packfile
warning: packfile .git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack cannot be accessed

... but the pull completed. Now I still have the unrelated changes in status, but then I try git fsck --full , I get:

$ 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

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 git pull would restore it, but apparently it doesn't...


EDIT, found these packfiles on another local copy of the same repo, but now this happens:

cp -av /second/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38* /first/myrepo/.git/objects/pack/
‘/second/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.idx’ -> ‘/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’ -> ‘/first/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack’
cp: cannot create regular file ‘/first/myrepo/.git/objects/pack/pack-65f501f2463a843b574db1ac1bde89b44e9acf38.pack’: Permission denied

But why do I get permission denied, I am the owner of those files?

$ 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

Just having the permissions rrr shouldn't make a difference, right ?! (although it seems they have been copied, the file sizes seem right)...

I would do new clone of repository somewhere else and then copy over working files to new clone. This way you would write unchecked changes over new repo and could commit it. I would skip .git and other repo specific files as well.

Ok, this is what I did - after that strange copy of the .pack file as above, I did:

$ git fsck --full
Checking object directories: 100% (256/256), done.
Checking objects: 100% (15506/15506), done.
dangling blob 35603bdc2deb1bbe87014c0fa7564f2ff077d2e8
dangling blob a2e54f6f31b87bbbe16a630cb4a938f597f07da1
dangling blob 60a6b39cd196dcd09e7b2246f3f2d9d2b0c12716
dangling blob 5a667c801bc4386b6c86c98f61f82df0399da3ca
dangling blob 16b0e85eaf256a4f0a2aeb7532929077fef92737
dangling blob 827a7209620a031935539e1a70ddb005edc52bfb

... which means it passed fine, but git status -uno was still showing too many "Changes not staged for commit...", so I did what @TimBiegeleisen suggested:

git reset --hard HEAD~2

git status -uno      # now only minimal "Changes not staged for commit"

git pull             # went back to current HEAD

git fsck --full      # same as above
git status -uno      # same as above

... and indeed, the git reset didn't lose my untracked logfiles, which is nice. So I guess, the repo is mostly recovered now - thanks all!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM