3 回答
TA贡献1943条经验 获得超7个赞
我有一个类似的问题。我的笔记本电脑在git操作期间电量耗尽。嘘。
我没有任何备份。(注意,Ubuntu One不是git的备份解决方案;它将用损坏的存储库有帮助地覆盖您的健全存储库。)
对于git向导,如果这是修复它的不好方法,请发表评论。但是,它确实为我工作了……至少是暂时的。
第1步:备份.git(实际上,我在更改某些步骤的每一步之间进行此操作,但是使用新的复制到名称,例如.git-old-1,.git-old-2等) :
cp -a .git .git-old
步骤2:执行 git fsck --full
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full
error: object file .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e is empty
fatal: loose object 8b61d0135d3195966b443f6c73fb68466264c68e (stored in .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e) is corrupt
步骤3:删除空文件。我想通了。反正还是空白。
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ rm .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e
rm: remove write-protected regular empty file `.git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e'? y
步骤3:git fsck再次运行。继续删除空文件。您还可以cd进入.git目录并运行find . -type f -empty -delete -print以删除所有空文件。最终git开始告诉我它实际上是在处理对象目录:
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full
Checking object directories: 100% (256/256), done.
error: object file .git/objects/e0/cbccee33aea970f4887194047141f79a363636 is empty
fatal: loose object e0cbccee33aea970f4887194047141f79a363636 (stored in .git/objects/e0/cbccee33aea970f4887194047141f79a363636) is corrupt
步骤4:删除所有空文件后,我最终开始git fsck实际运行:
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full
Checking object directories: 100% (256/256), done.
error: HEAD: invalid sha1 pointer af9fc0c5939eee40f6be2ed66381d74ec2be895f
error: refs/heads/master does not point to a valid object!
error: refs/heads/master.u1conflict does not point to a valid object!
error: 0e31469d372551bb2f51a186fa32795e39f94d5c: invalid sha1 pointer in cache-tree
dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2
missing blob 8b61d0135d3195966b443f6c73fb68466264c68e
missing blob e89896b1282fbae6cf046bf21b62dd275aaa32f4
dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a
missing blob caab8e3d18f2b8c8947f79af7885cdeeeae192fd
missing blob e4cf65ddf80338d50ecd4abcf1caf1de3127c229
步骤5:尝试git reflog。失败,因为我的头坏了。
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git reflog
fatal: bad object HEAD
步骤6:Google。找到这个。手动获取reflog的最后两行:
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ tail -n 2 .git/logs/refs/heads/master
f2d4c4868ec7719317a8fce9dc18c4f2e00ede04 9f0abf890b113a287e10d56b66dbab66adc1662d Nathan VanHoudnos <nathanvan@gmail.com> 1347306977 -0400 commit: up to p. 24, including correcting spelling of my name
9f0abf890b113a287e10d56b66dbab66adc1662d af9fc0c5939eee40f6be2ed66381d74ec2be895f Nathan VanHoudnos <nathanvan@gmail.com> 1347358589 -0400 commit: fixed up to page 28
步骤7:请注意,从步骤6中我们了解到HEAD当前指向最后的提交。因此,让我们尝试仅查看父提交:
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git show 9f0abf890b113a287e10d56b66dbab66adc1662d
commit 9f0abf890b113a287e10d56b66dbab66adc1662d
Author: Nathan VanHoudnos <nathanvan@XXXXXX>
Date: Mon Sep 10 15:56:17 2012 -0400
up to p. 24, including correcting spelling of my name
diff --git a/tex/MCMC-in-IRT.tex b/tex/MCMC-in-IRT.tex
index 86e67a1..b860686 100644
--- a/tex/MCMC-in-IRT.tex
+++ b/tex/MCMC-in-IRT.tex
有效!
步骤8:所以现在我们需要将HEAD指向9f0abf890b113a287e10d56b66dbab66adc1662d。
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git update-ref HEAD 9f0abf890b113a287e10d56b66dbab66adc1662d
哪个没抱怨。
步骤9:看看fsck怎么说:
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full
Checking object directories: 100% (256/256), done.
error: refs/heads/master.u1conflict does not point to a valid object!
error: 0e31469d372551bb2f51a186fa32795e39f94d5c: invalid sha1 pointer in cache-tree
dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2
missing blob 8b61d0135d3195966b443f6c73fb68466264c68e
missing blob e89896b1282fbae6cf046bf21b62dd275aaa32f4
dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a
missing blob caab8e3d18f2b8c8947f79af7885cdeeeae192fd
missing blob e4cf65ddf80338d50ecd4abcf1caf1de3127c229
步骤10:高速缓存树中的无效sha1指针似乎来自于(现已过时)索引文件(source)。所以我杀了它并重置了仓库。
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ rm .git/index
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git reset
Unstaged changes after reset:
M tex/MCMC-in-IRT.tex
M tex/recipe-example/build-example-plots.R
M tex/recipe-example/build-failure-plots.R
步骤11:再次查看fsck ...
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full
Checking object directories: 100% (256/256), done.
error: refs/heads/master.u1conflict does not point to a valid object!
dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2
dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a
在晃来晃去斑点不是错误。我不关心master.u1冲突,现在它可以正常工作了,我不想再碰它了!
第12步:掌握本地编辑信息:
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: tex/MCMC-in-IRT.tex
# modified: tex/recipe-example/build-example-plots.R
# modified: tex/recipe-example/build-failure-plots.R
#
< ... snip ... >
no changes added to commit (use "git add" and/or "git commit -a")
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git commit -a -m "recovering from the git fiasco"
[master 7922876] recovering from the git fiasco
3 files changed, 12 insertions(+), 94 deletions(-)
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git add tex/sept2012_code/example-code-testing.R
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git commit -a -m "adding in the example code"
[master 385c023] adding in the example code
1 file changed, 331 insertions(+)
create mode 100644 tex/sept2012_code/example-code-testing.R
因此,希望将来对人们有用。我很高兴它奏效。
TA贡献1794条经验 获得超8个赞
git对象文件已损坏(也如其他答案所指出)。这可能在机器崩溃等情况下发生。
我有同样的事情。在阅读了其他顶级答案之后,我发现了使用以下命令修复损坏的git存储库的最快方法(在包含该.git文件夹的git工作目录中执行):
(确保首先备份您的git仓库文件夹!)
find .git/objects/ -type f -empty | xargs rm
git fetch -p
git fsck --full
这将首先删除所有导致整个存储库损坏的空对象文件,然后从远程存储库中获取丢失的对象(以及最新更改),然后进行完整的对象存储检查。在这一点上,应该可以成功执行而不会出现任何错误(尽管可能还会有一些警告!)
PS。这个答案表明您在某个地方(例如,在GitHub上)有一个git存储库的远程副本,而损坏的存储库是与仍处于正常状态的远程存储库绑定的本地存储库。如果不是这种情况,请不要尝试按照我的建议进行修复。
TA贡献1852条经验 获得超1个赞
解决了此问题,删除了git fsck检测到的各种空文件,然后运行简单的git pull。
我感到失望的是,即使文件系统也实现了日记功能和其他“事务性”技术来保持fs的正常运行,由于电源故障或设备空间不足,git可能会陷入损坏状态(并且无法自行恢复)。
- 3 回答
- 0 关注
- 2543 浏览
添加回答
举报