繁体   English   中英

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

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

我不知道这台计算机可能出了什么问题,但是我关闭了它,半个小时后启动了它,执行git status -uno ,它告诉我一个子模块“不是”某种东西。 然后我意识到.git/submodules目录为空。 然后,我从其他地方复制这些文件, git status -uno给了我一系列无关的更改(一个.txt文件突然变成目录了?)。 然后我尝试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

...但是拉力完成了。 现在我的状态仍然没有关系,但是我尝试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

有什么办法可以恢复此存储库,以使当前未检查的文件仍然存在? (我有一些我仍然需要但不应该在更大范围内查看的日志)。 我本来希望git pull可以恢复它,但是显然不会...


编辑,在同一仓库的另一个本地副本上找到这些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

但是,为什么我是那些文件的所有者,但我却拒绝了权限?

$ 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

仅拥有rrr权限就不会有所不同,对吧? (尽管它们似乎已被复制,但文件大小似乎正确)...

我会在其他地方进行存储库的新克隆,然后将工作文件复制到新克隆。 这样,您将在新的仓库中写入未经检查的更改并可以提交。 我也会跳过.git和其他回购专用文件。

好的,这就是我所做的-在完成上述.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

...这意味着它通过了,但是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

...确实, git reset不会丢失我的未跟踪日志文件,这很好。 所以我想现在回购大部分已经恢复了-谢谢大家!

暂无
暂无

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

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