如何处理 git gc fatal: bad object refs/remotes/origin/HEAD error: failed to run repack
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37145151/
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
How to handle git gc fatal: bad object refs/remotes/origin/HEAD error: failed to run repack
提问by Ryan
I randomly hit list today while trying to garbage collect.
我今天在尝试垃圾收集时随机点击了列表。
$ git gc
fatal: bad object refs/remotes/origin/HEAD
error: failed to run repack
How do I deal with this?
我该如何处理?
回答by petrelharp
I don't understand the ramifications of this, but as suggested in this thread, when I encountered this I just did
我不明白这会带来什么后果,但正如这个帖子中所建议的那样,当我遇到这个问题时,我就是这样做的
$ mv .git/refs/remotes/origin/HEAD /tmp
(keeping it around just in case) and then
(保留它以防万一)然后
$ git gc
worked without complaining; I haven't run into any problems.
毫无怨言地工作;我没有遇到任何问题。
回答by Trenton
The problem that I ran into (which is the same problem that @Stavarengo mentioned in this commentabove) is that the default remote branch (develop
in my case) had been deleted, but was still referenced in .git/refs/remotes/origin/HEAD
.
我遇到的问题(与@Stavarengo 在上面的评论中提到的问题相同)是默认远程分支(develop
在我的情况下)已被删除,但仍然在.git/refs/remotes/origin/HEAD
.
Opening .git/refs/remotes/origin/HEAD
in my editor showed this:
.git/refs/remotes/origin/HEAD
在我的编辑器中打开显示:
ref: refs/remotes/origin/develop
I carefullyedited it to point at my new default branch and all was well:
我仔细编辑它以指向我的新默认分支,一切都很好:
ref: refs/remotes/origin/master
The clue that tipped me off was that running git prune
showed this error:
提示我的线索是运行git prune
显示此错误:
> git prune
warning: symbolic ref is dangling: refs/remotes/origin/HEAD
回答by WilQu
After seeing Trenton's answer, I looked at my .git/refs/remotes/origin/HEAD
and saw that it was also pointing to an old branch that is now deleted.
看到特伦顿的回答后,我看了看我的.git/refs/remotes/origin/HEAD
,发现它也指向一个现在被删除的旧分支。
But instead of editing the file myself, I tried Ryan's solution:
但是我没有自己编辑文件,而是尝试了 Ryan 的解决方案:
git remote set-head origin --auto
It automatically set the file to the new branch, and git gc
worked fine after that.
它会自动将文件设置到新分支,git gc
之后工作正常。
回答by Ryan
I thought the solution was the following since this seemed to work, but it turns out to not actually solve the problem.
我认为解决方案如下,因为这似乎有效,但事实证明并没有真正解决问题。
git remote set-head origin --auto
回答by Conal Trinitrotoluene Da Costa
Looks like your symbolic-refs might be broken... Try the replacing it with your default branch like this: For example, my default branch is master
看起来您的符号引用可能已损坏...尝试将其替换为您的默认分支,如下所示:例如,我的默认分支是master
$ git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/master
$ git fetch --prune
$ git gc
That should fix it.
那应该解决它。
回答by JeffP
If you're using git worktrees, make sure you're doing a
如果您使用的是 git worktrees,请确保您正在执行
git worktree prune
before running
跑步前
git gc
I had a worktree get corrupted and this seemed to do the trick after removing the corrupted worktree. git prune
by itself didn't seem to work.
我有一个工作树损坏了,这似乎在删除损坏的工作树后起作用了。git prune
本身似乎不起作用。