运行git pull后如何解决错误bad object refs/heads/main(1)

jm81lzqq  于 2023-01-15  发布在  Git
关注(0)|答案(1)|浏览(1745)

当我在Mac上的终端中运行git pull时,如何解决此错误?

remote: Enumerating objects: 115, done.
remote: Counting objects: 100% (115/115), done.
remote: Compressing objects: 100% (66/66), done.
remote: Total 104 (delta 71), reused 63 (delta 30), pack-reused 0
Receiving objects: 100% (104/104), 3.92 MiB | 3.16 MiB/s, done.
Resolving deltas: 100% (71/71), completed with 9 local objects.
fatal: bad object refs/heads/main (1)
error: https://github.com/[...domain name...]/website.git did not send all necessary objects

背景是我有一个网站,通常工作起来没有问题。我在RStudio中创建了它,并与github同步。Netlify从那里开始。下面是设置的基础:https://www.apreshill.com/blog/2020-12-new-year-new-blogdown/.
在RStudio中进行更改后,我通常可以提交更改,然后推送更改。但这次,它是这样的:

! [rejected]        HEAD -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/[domain name]/website.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again

所以我转到终端,将工作目录更改为存储文件的位置,然后运行git pull。然后我得到上面提到的fatal: bad object refs/heads/main (1)错误。基于How to handle git gc fatal: bad object refs/remotes/origin/HEAD error?,我尝试git gc,并得到以下错误:

error: bad ref for .git/logs/HEAD (1)
error: bad ref for .git/logs/refs/heads/main (1)
fatal: bad object refs/heads/main (1)
fatal: failed to run repack

我还尝试了git remote set-head origin --auto,然后git gc,得到了与上面直接相同的错误。
如果我运行cat .git/refs/remotes/origin/HEAD,它会说:refs/remotes/origin/main.
最后,我在git pull之前尝试了git reset --hard,这给了我最初的错误。
我不确定此时该怎么做。我完全可以从远程服务器获取所有内容并重做本地更改。

j91ykkif

j91ykkif1#

在你的仓库中存在一个名为.git/refs/heads/main (1)的文件,这也意味着本地分支main (1)存在。该名称包含一个空格,这是分支名称中不允许的(参见here),这可能是错误的原因。
后缀(1)可能是意外出现的。请尝试先将其从文件名中删除,然后再运行其他操作。

相关问题