这里写自定义目录标题
服务器意外断电后,导致git仓库数据损坏,在客户端pull
和clone
均无法成功,出错如下:
$ git pull
fatal: failed to read object 7c45ff324431a754692e4bdb69225d8fe979aed5: Invalid argument
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
$ git clone ssh://git@192.168.1.238/jw-project.git
Cloning into 'jw-project'...
fatal: failed to read object 7c45ff324431a754692e4bdb69225d8fe979aed5: Invalid argument
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
既然clone
都不行,说明不是本地仓库的问题,只能去服务器上查原因了。
git@gotech-desktop:~/repositories/jw-project.git$ git log
fatal: failed to read object 7c45ff324431a754692e4bdb69225d8fe979aed5: Invalid argument
git@gotech-desktop:~/repositories/jw-project.git$ git fsck --full
fatal: failed to read object 14670d8b18182c991c971058a3eeac4066a9bcfa: Invalid argument
基本上git的命令都用不了了。查看head
节点
git@gotech-desktop:~/repositories/jw-project.git$ cat HEAD
ref: refs/heads/master
git@gotech-desktop:~/repositories/jw-project.git$ cat refs/heads/master
7c45ff324431a754692e4bdb69225d8fe979aed5
git@gotech-desktop:~/repositories/jw-project.git$ cd objects/7c
git@gotech-desktop:~/repositories/jw-project.git/objects/7c$ ls -l 45ff324431a754692e4bdb69225d8fe979aed5
-r--r--r-- 1 git git 0 Nov 26 11:08 45ff324431a754692e4bdb69225d8fe979aed5
这里注意refs/heads/master
中记录的object
的hash
值是这个object
的目录名字(2个字符,也就是7c)和文件名字的联合值。可以看到这个object
大小是0。我从本地仓库找到这个object
将其覆盖后,错误变成新的:
$ git clone ssh://git@192.168.1.238/jw-project.git
Cloning into 'jw-project'...
error: git upload-pack: git-pack-objects died with error.
fatal: git upload-pack: aborting due to possible repository corruption on the remote side.
remote: fatal: failed to read object 6f60eef4fba13b61b9adf8ee2c4222a9b58d101b: Invalid argument
remote: aborting due to possible repository corruption on the remote side.
fatal: early EOF
fatal: index-pack failed
虽然错误提示办了,但是可以看到这个object是一个问题,大小还是0,继续替换,最后大概有20个文件,都替换完成后,成功了,客户端可以正常clone和pull了。
不过这种方式首先要找到谁是最后一次上传的那个人,用他的本地仓库的这些文件才行。