git status 显示致命:坏对象 HEAD

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

git status shows fatal: bad object HEAD

gitgithub

提问by dotnetrocks

I have a problem with git on Windows Azure. Git status shows - "fatal: bad object HEAD" and I tried running:

我在 Windows Azure 上遇到了 git 问题。Git 状态显示 - “致命:坏对象 HEAD”,我尝试运行:

 git fsck --full
 git gc

But git fsckshows:

git fsck显示:

broken link from  commit 739df633f185ce5d1ab7eb97d619b28e7d81185a
              to    tree 2a6d4876d135c1fa7cbe1348c62570006e895fc5
broken link from  commit 9c7eae5ffed34dbfac977e515dee675626b59f93
              to    tree 400132d215ab9aced883a9971e648b82624b2032
broken link from  commit 9c7eae5ffed34dbfac977e515dee675626b59f93
              to  commit 4a49af0a0cb64a0a0415734b11772d6df18561fb
broken link from  commit bc3072f30e71c616a8196089e19a67a2c9c0a5ad
              to    tree 0aa813c183487d0a1b1f7ae81501ca7a1168283f
broken link from  commit d3bb4f8545e91ec8ace15ad31a3147d92a1d4242
              to    tree 4682108accd8e72fe68858232386dffe60f9f02d
broken link from  commit 6b34795c4b54286301bcdc0ed254a04c132cb2ad
              to    tree 5c57dd3222d11924dba841d3cae517bdc9220601
broken link from  commit d70172d855391b93bc1c5eeb9b4226df525dfc6e
              to  commit 390c8cbd527c8e707c51e25142e54421f4dd3948
broken link from  commit cc05e8d2e3733693ebb67d697ae4b65e51fea79a
              to  commit 32f081f8b901425fd1e8898478f0551970bee0f5
broken link from    tree 6a75ed6d0311d800078e77f43d427d128372d5bc
              to    blob 4a064d610c0e7207967d59934c8bc5f491f26dae
broken link from    tree 6a75ed6d0311d800078e77f43d427d128372d5bc
              to    tree 5c06ec964dcbade49287d0f36efe1f7b60f446e3
broken link from    tree b4855fa6734b5652a93a9b799eafe47fad0d13a0
              to    blob 3e1fb421613dc9066cbf9c95eddc61619a9f8eed
broken link from    tree b4855fa6734b5652a93a9b799eafe47fad0d13a0
              to    tree 556a50048d42346c283c94b78ea278ba1d57d251
broken link from    tree 289c03409370c4ca7c12266ce2822a2976bd032b
              to    blob 3abf3c48ada45f63404dcf4d675ddfdadcfa83c6
broken link from    tree 289c03409370c4ca7c12266ce2822a2976bd032b
              to    blob 3fa569892003b468ed1301426dd6d96d9644be3c
broken link from    tree 289c03409370c4ca7c12266ce2822a2976bd032b
              to    blob 0a9a54a51e84f3bc34122dbce1146d895fcbe22c
broken link from    tree 289c03409370c4ca7c12266ce2822a2976bd032b
              to    blob 3fa48873564361b4d95830803ae77f79eeafaf5b

git branchshows - *master

git branch显示 - *大师

采纳答案by Ikke

Your repository is corrupt. That means data is lost that cannot be recovered by git itself. If you have another clone of this repository, you can recover the objects from there, or make a new clone.

您的存储库已损坏。这意味着 git 本身无法恢复的数据丢失了。如果您有此存储库的另一个克隆,您可以从那里恢复对象,或创建一个新的克隆。

fatal: bad object HEADmeans the branch referenced from HEAD is pointing to a bad commit object, which can mean it's missing or corrupt.

fatal: bad object HEAD意味着从 HEAD 引用的分支指向错误的提交对象,这可能意味着它丢失或损坏。

From the output of git fsck, you can see there are a few tree, blob and commit objects missing.

从 的输出中git fsck,您可以看到缺少一些树、blob 和提交对象。

Note that using git itself is not enough to keep data safe. You still need to back it up in cases of corruption.

请注意,使用 git 本身不足以保证数据安全。您仍然需要在损坏的情况下对其进行备份。

回答by ganesh

try this : worked for me rm -rf .git

试试这个:对我来说有效 rm -rf .git

then copy .gitfrom other clone

然后从其他克隆复制.git

cp <pathofotherrepository>/.git . -r

cp <pathofotherrepository>/.git . -r

then do

然后做

git init

git init

this should solve your problem , ALL THE BEST

这应该可以解决您的问题,一切顺利

回答by Mahesh Gareja

This happened because by mistake I removed some core file of GIT. Try this its worked for me.

发生这种情况是因为我错误地删除了 GIT 的一些核心文件。试试这个它对我有用。

re-initialize git

重新初始化git

git init

fetch data from remote

从远程获取数据

git fetch

Now check all your changes and git status by

现在通过以下方式检查您的所有更改和 git 状态

git status

回答by serup

I had a similar problem and what worked for me was to make a new clone from my original repository

我有一个类似的问题,对我有用的是从我的原始存储库制作一个新的克隆

回答by jan-glx

Your repository is broken. But you can probably fix it AND keep your edits:

您的存储库已损坏。但是您可能可以修复它并保留您的编辑:

  1. Back up first: cp your_repository your_repositry_bak
  2. Clone the broken repository (still works): git clone your_repository your_repository_clone
  3. Replace the broken .git folder with the one from the clone: rm -rf your_repository/.git && cp your_repository_clone/.git your_repository/ -r
  4. Delete clone & backup (if everything is fine): rm -r your_repository_*
  1. 先备份: cp your_repository your_repositry_bak
  2. 克隆损坏的存储库(仍然有效): git clone your_repository your_repository_clone
  3. 用克隆中的文件夹替换损坏的 .git 文件夹: rm -rf your_repository/.git && cp your_repository_clone/.git your_repository/ -r
  4. 删除克隆和备份(如果一切正常): rm -r your_repository_*

回答by Felipe Pereira

In my case the error came out of nowhere, but didn't let me push to the remote branch.

在我的情况下,错误无处不在,但没有让我推送到远程分支。

git fetch origin

And that solved it.

这解决了它。

I agree this may not solve the issue for everyone, but before trying a more complex approach give it a shot at this one, nothing to loose.

我同意这可能无法解决每个人的问题,但在尝试更复杂的方法之前,先试一试这个方法,没什么可松懈的。

回答by jwg

I managed to fix a similar problem to this when some of git's files were corrupted:

当某些 git 文件损坏时,我设法解决了与此类似的问题:

https://stackoverflow.com/a/30871926/1737957

https://stackoverflow.com/a/30871926/1737957

In my answer on that question, look for the part where I had the same error message as here:

在我对那个问题的回答中,查找我有与此处相同的错误消息的部分:

fatal: bad object HEAD.

You could try following what I did from that point on. Make sure to back up the whole folder first.

从那时起,您可以尝试遵循我所做的事情。确保先备份整个文件夹。

Of course, your repository might be corrupted in a completely different way, and what I did won't solve your problem. But it might give you some ideas! Git internals seem like magic, but it's really just a bunch of files which can be edited, moved, deleted the same as any others. Once you have a good idea of what they do and how they fit together you have a good chance of success.

当然,您的存储库可能以完全不同的方式损坏,而我所做的并不能解决您的问题。但它可能会给你一些想法!Git 内部结构看起来很神奇,但它实际上只是一堆文件,可以像任何其他文件一样进行编辑、移动、删除。一旦您对它们的作用以及它们如何组合有了很好的了解,您就有很大的成功机会。

回答by ulas korpe

Make a copy of your git dir in your local host and run git initthere once again. Push the project to a brand new reprository.

在本地主机中复制 git 目录并git init再次运行。将项目推送到全新的存储库。

回答by Ricardo

I solved this by copying the branch data (with the errors) to my apple laptop local git folder.

我通过将分支数据(带有错误)复制到我的苹果笔记本电脑本地 git 文件夹来解决这个问题。

Somehow in the terminal and when running: git status, tells me more specific data where the error occurs. If you look under the errors, hopefully you see a list of folders with error. In my case GIT showed the folder which was responsible for the error. Deleting that folder and commiting the branche, I succeeded. git status was working again the other devices updating by git pull; everything working again on every machine.

不知何故在终端和运行时:git status,告诉我发生错误的更具体的数据。如果您查看错误下方,希望您看到错误文件夹列表。在我的情况下,GIT 显示了导致错误的文件夹。删除该文件夹并提交分支,我成功了。git status 再次工作,其他设备通过 git pull 更新;一切都在每台机器上重新运行。

Hopefully this will work for you also.

希望这也适用于您。

回答by wdonahoe

This is unlikely to be the source of your problem - but if you happen to be working in .NET you'll end up with a bunch of obj/folders. Sometimes it is helpful to delete all of these obj/folders in order to resolve a pesky build issue.

这不太可能是您的问题的根源 - 但如果您碰巧在 .NET 中工作,您最终会得到一堆obj/文件夹。有时,删除所有这些obj/文件夹有助于解决讨厌的构建问题。

I received the same fatal: bad object HEADon my current branch (master) and was unable to run git statusor to checkout any other branch (I always got an error refs/remote/[branch] does not point to a valid object).

fatal: bad object HEAD在我当前的分支(主)上收到了同样的消息,并且无法运行git status或结帐任何其他分支(我总是得到一个error refs/remote/[branch] does not point to a valid object)。

If you want to delete all of your objfolders, don't get lazy and allow .git/objectsinto the mix. That folder is where all of the actual contents of your git commits go.

如果您想删除所有obj文件夹,请不要偷懒并允许.git/objects混合。该文件夹是 git 提交的所有实际内容所在的位置。

After being close to giving up I decided to look at which files were in my recycle bin, and there it was. Restored the file and my local repository was like new.

在接近放弃之后,我决定查看回收站中的哪些文件,结果就在那里。恢复了文件,我的本地存储库就像新的一样。