简体   繁体   English

从文件“不是GIT打包文件”中恢复Git存储库

[英]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. 我不知道这台计算机可能出了什么问题,但是我关闭了它,半个小时后启动了它,执行git status -uno ,它告诉我一个子模块“不是”某种东西。 Then I realize the .git/submodules dir is empty. 然后我意识到.git/submodules目录为空。 Then I copy those from elsewhere, git status -uno gave me a bunch of unrelated changes (one .txt file became suddenly a directory ?). 然后,我从其他地方复制这些文件, git status -uno给了我一系列无关的更改(一个.txt文件突然变成目录了?)。 Then I try git pull , it gives me a ton of 然后我尝试git pull ,它给了我很多

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 ,我得到:

$ 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... 我本来希望git pull可以恢复它,但是显然不会...


EDIT, found these packfiles on another local copy of the same repo, but now this happens: 编辑,在同一仓库的另一个本地副本上找到这些packfile,但是现在发生了:

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 ?! 仅拥有rrr权限就不会有所不同,对吧? (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. 我也会跳过.git和其他回购专用文件。

Ok, this is what I did - after that strange copy of the .pack file as above, I did: 好的,这就是我所做的-在完成上述.pack文件的奇怪副本之后,我做了:

$ 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 status -uno仍然显示太多“未上演更改以提交...”,所以我做了@TimBiegeleisen建议的操作:

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. ...确实, git reset不会丢失我的未跟踪日志文件,这很好。 So I guess, the repo is mostly recovered now - thanks all! 所以我想现在回购大部分已经恢复了-谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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