git 致命:坏对象 HEAD

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25797315/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:27:23  来源:igfitidea点击:

fatal: bad object HEAD

git

提问by H Abdi

Can somebody help me to solve this problem. I had made a previous post about this but I couldn't solve it through those answers. Please help:)

有人可以帮我解决这个问题。我之前写过一篇关于这个的帖子,但我无法通过这些答案解决它。请帮忙:)

I have tried to run git fsck --fulland I get :

我试过跑git fsck --full,我得到:

Checking object directories: 100% (256/256), done.
error: HEAD: invalid sha1 pointer 15044de63184bed22f9be9f48fd63a3a7652eea4
error: refs/heads/master does not point to a valid object!
notice: No default references
dangling blob f4ffb48ece75b45ec593146216a2ecae5a5b2194
dangling blob f37ffd41d80a2d07258d0b8fa7118d236d480fc0
dangling blob f1ff1fa538a538d9085e573f60ad11e8e7f5395e
dangling blob f9ff6bdaf08fdbf9001ff44d2aa1a49092c20ad1
dangling blob f97f1a223ef3ca33f55d51ae25d98d3b5b2f9ece

回答by Jayen

In my case, I edited .git/refs/remotes/origin/HEAD. I couldn't get git update-refto work, but that seems to be the recommended way.

就我而言,我编辑了.git/refs/remotes/origin/HEAD. 我无法开始git update-ref工作,但这似乎是推荐的方式。

So if git checkout (<branch> | <commit>)doesn't work, you should try something like git update-ref HEAD ref:masteror just try editing .git/HEAD.

因此,如果git checkout (<branch> | <commit>)不起作用,您应该尝试类似的操作git update-ref HEAD ref:master或尝试编辑.git/HEAD.

回答by henrikstroem

I had the same problem. Simply doing a git pull origin masterfixed it, and left my local edits intact.

我有同样的问题。只需git pull origin master修复它,并保持我的本地编辑完好无损。

回答by VonC

"invalid sha1 pointer" in combination of git gcwas seen before (git for windows issue 423)

“无效的 sha1 指针”组合git gc之前见过(适用于 Windows 的 git 问题 423

git 2.7 (Q4 2015) will fix this:

git 2.7 (Q4 2015) 将解决这个问题:

See commit 14886b4, commit 8c845cd(28 Sep 2015) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster--in commit 1018f3e, 15 Oct 2015)

请参阅Johannes Schindelin ( ) 的commit 14886b4commit 8c845cd(2015 年 9 月 28 日(由Junio C Hamano合并-- --commit 1018f3e,2015 年 10 月 15 日)dscho
gitster

"git gc" used to barf when a symbolic ref has gone dangling (e.g. the branch that used to be your upstream's default when you cloned from it is now gone, and you did "fetch --prune").

" git gc" 过去常常在符号 ref 悬空时呕吐(例如,从它克隆时曾经是上游默认的分支现在已经消失了,而你做到了 " fetch --prune")。

More precisely:

更确切地说:

pack-objects: do not get distracted by broken symrefs

It is quite possible for, say, a remote HEAD to become broken, e.g. when the default branch was renamed.

We should still be able to pack our objects when such a thing happens; simply ignore broken symrefs (because they cannot matter for the packing process anyway).

pack-objects: 不要被损坏的 symrefs 分心

例如,远程 HEAD 很可能损坏,例如当默认分支被重命名时。

当这种事情发生时,我们应该仍然能够打包我们的对象;只需忽略损坏的 symrefs(因为无论如何它们对打包过程无关紧要)。

回答by Marcus

I had the same problem that appened to me because of some problems with git objects. The only way to fix them is to do a git clone in a different folder and then copy-paste all in the old folder.

由于 git 对象的一些问题,我遇到了同样的问题。修复它们的唯一方法是在不同的文件夹中执行 git clone,然后将所有内容复制粘贴到旧文件夹中。

I will lee you know if i will find a different solution.

我会告诉你我是否会找到不同的解决方案。

Regards

问候