git repo 损坏的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14569172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problems with corrupt git repo
提问by epsilones
My git repo got corrupted while running a find and replace command (See here: Git reset failing after find and replace). So I deleted some pack files about which git told me that there were not reachable. So I ran rm ./.git/index, git reset. When running git commit, I got this message :
我的 git 存储库在运行查找和替换命令时损坏(请参阅此处:查找和替换后 Git 重置失败)。所以我删除了一些 git 告诉我无法访问的包文件。所以我运行 rm ./.git/index, git reset。运行 git commit 时,我收到以下消息:
fatal: corrupt tree sha $someSHA
Finally git fsck, my working directory went clean and I was able to commit. The pb now is that when I run git checkout some_other_branch, I got this message
最后 git fsck,我的工作目录变得干净,我能够提交。现在的 pb 是当我运行 git checkout some_other_branch 时,我收到了这条消息
fatal: unable to read tree $someSHA
(The $someSHA appearing are the same). Someone could help me ?
(出现的 $someSHA 是相同的)。有人可以帮助我吗?
Edit 1 :
编辑1:
when I run git fsck --full, I get a serie of
当我运行 git fsck --full 时,我得到一系列
error: refs/remotes/repo0/master does not point to a valid object!
error: refs/remotes/repo1/new-version does not point to a valid object!
...
then a serie of
然后是一系列
broken link from tree d935b909f76ea92728d71038d0a67384353e65e1
to blob 05b97658ebd47fee25b76d80ac76cbd07d77961d
...
and then some missing blobs...
然后一些丢失的斑点......
Edit 2 :
编辑2:
I ran git log --raw --all --full-history -- subdir/my-file, and I get
我运行了 git log --raw --all --full-history -- subdir/my-file,然后我得到
error: refs/remotes/repo0/master does not point to a valid object!
error: refs/remotes/repo1/new-version does not point to a valid object!
...
error: Could not read 9096eb9d9dcbdf15a04e0a7c78a3744936f82ac7
fatal: cannot simplify commit 8dfd8e3d5b698dc979300d93d8e89a757abf6ec6 (because of 9096eb9d9dcbdf15a04e0a7c78a3744936f82ac7)
Edit 3 :
编辑3:
I ran git fsck --full
, the I get numerous lines as so
我跑了git fsck --full
,我得到了很多行
error: packfile .git/objects/pack/pack-fbfd8042e1e96bf5ffff88f9b5a230b8f5e4d4c4.pack does not match index
fatal: packfile .git/objects/pack/pack-fbfd8042e1e96bf5ffff88f9b5a230b8f5e4d4c4.pack cannot be accessed
...
when running git checkout
to another branch I got numerous messages as so :
当跑到git checkout
另一个分支时,我收到了很多消息:
error: packfile .git/objects/pack/pack-3e7a0c040a5e3d1c21b91256d583424d82a59706.pack does not match index
warning: packfile .git/objects/pack/pack-3e7a0c040a5e3d1c21b91256d583424d82a59706.pack cannot be accessed
....
fatal: unable to read tree 2ad71d368b65eff0b6fec1ef72c6fdde6e80edad
Edit 4 :
编辑4:
following the suggested answer, I unpacked the files and when I checked out, I got some lines as so :
按照建议的答案,我解压缩了文件,当我签出时,我得到了一些这样的行:
error: packfile .git/objects/pack/pack-fbfd8042e1e96bf5ffff88f9b5a230b8f5e4d4c4.pack does not match index
warning: packfile .git/objects/pack/pack-fbfd8042e1e96bf5ffff88f9b5a230b8f5e4d4c4.pack cannot be accesse....
and then a serie of lines beginning with
然后是一系列以
error: Your local changes to the following files would be overwritten by checkout:
.idea_local_work/.name
.idea_local_work/libraries/sass_stdlib.xml
.idea_local_work/scopes/scope_settings.xml
... and then aborting
回答by Chronial
First: Make a backup of your .git
directory in case you corrupt things more in this process. Then:
第一:备份您的.git
目录,以防您在此过程中损坏更多内容。然后:
- Put back the best version of the packfiles you have available.
For each of the corrupt packfiles, run:
mv .git/objects/pack/pack-**yourpack**.pack oldpack git unpack-objects -r < oldpack
Run
git fsck --full
andgit checkout
again, give us the output.Looks like now you should be able to check out, but you will have to run
git checkout -f **yourbranch**
, as you have changes in your working dir that are not yet committed. These changes will get lost when you rungit checkout -f
, though.
- 放回可用的包文件的最佳版本。
对于每个损坏的包文件,运行:
mv .git/objects/pack/pack-**yourpack**.pack oldpack git unpack-objects -r < oldpack
运行
git fsck --full
并git checkout
再次,给我们的输出。看起来现在您应该可以检出,但是您必须运行
git checkout -f **yourbranch**
,因为您的工作目录中有尚未提交的更改。git checkout -f
但是,当您运行 时,这些更改将丢失。