将破碎的git分支设置为分离的头

将破碎的git分支设置为分离的头

问题描述:

在提交过程中断电后,我的git存储库中的某个分支遭到损坏。我做了git fsck --full并删除了所有空对象文件,直到fsck递给我:将破碎的git分支设置为分离的头

Checking object directories: 100% (256/256), done. 
Checking objects: 100% (894584/894584), done. 
error: refs/heads/git-annex does not point to a valid object! 
Checking connectivity: 862549, done. 

然后我用git fsck --lost-found找到我的最后一个良好的悬挂提交的git-annex分支。我检查了它。

我希望这是我的替代品git-annex HEAD。我试过git checkout -b git-annex,但得到该分支已经存在。所以我尝试git branch -d git-annex,但得到error: Couldn't look up commit object for 'refs/heads/git-annex'

如何摆脱破损的git-annex分支以将其设置为我想要的提交?我已经尝试删除.git/refs/heads/git-annex,但这不起作用。谢谢。

+0

当您想放弃旧分支提示时使用'-B',例如'git checkout -B git-annex 1a2b3cd' – jthill

这对我的作品(“作弊”来插入一个破碎的分支,并试图删除它时,看到了同样的错误之后):

git branch -f broked HEAD # or some other valid point 
git branch -d broked 

第二个命令的抱怨,因为它会删除破碎的裁判。 git/packed-refs(这是我认为它必须是删除.git/refs/heads/git-annex无用的地方)。 (但是分支名称“git-annex”让我想知道你是否在使用git-annex,比如在回购站之外存储大文件的东西,我自己并没有使用过,也不确定这是否会改变任何内容。)

+0

其实我所需要的只是第一个命令,我可以用它来设置'git-annex'给悬挂提交。现在'git fsck'是干净的。感谢那。 我的确在使用git-annex,但我确信在这种情况下这不会改变任何东西。 –