我不知道这台计算机出了什么问题,但我把它关闭了,半小时后我启动它,做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
能够恢复它,但显然它并没有......
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
不应该有所作为,对吧?! (虽然看起来它们已被复制,文件大小似乎正确)...
答案 0 :(得分:1)
我会在其他地方新建一个存储库,然后将工作文件复制到新克隆。这样你就可以在新的repo上编写未经检查的更改,并且可以提交它。我也会跳过.git和其他repo特定文件。
答案 1 :(得分:0)
好的,这就是我所做的 - 在上面的.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
并没有丢失我未跟踪的日志文件,这很好。所以我猜,回购现在大部分已经恢复了 - 谢谢大家!