Git 致命:坏对象 refs/heads 2/master

A. *_*man 9 git github

几个月没有在某个静态网站上工作后,我回来尝试从 GitHub 存储库中提取更改。

\n

发生以下fatal: bad object refs/heads 2/master错误。

\n
(base) \xe2\x9e\x9c  github_repo git:(master) \xe2\x9c\x97 git pull\nremote: Enumerating objects: 21, done.\nremote: Counting objects: 100% (3/3), done.\nremote: Total 21 (delta 3), reused 3 (delta 3), pack-reused 18\nUnpacking objects: 100% (21/21), 6.95 KiB | 790.00 KiB/s, done.\nfatal: bad object refs/heads 2/master\nerror: https://github.com/asafmaman101/asafmaman101.github.io.git did not send all necessary objects\n
Run Code Online (Sandbox Code Playgroud)\n

尝试了 StackOverflow 上类似问题的一些解决方案,并尝试更新我的 mac 上的 Git 版本。

\n

没有任何帮助。\n我试图阻止删除本地副本并重新克隆存储库,因为我不想丢失本地更改。还有其他想法吗?

\n

Rob*_*art 27

I had a similar problem with a " 2" suffix being added to a filename within the .git directory. The git repository is in a directory synced by iCloud Drive, so presumably iCloud in its infinite wisdom added the suffix during a sync operation.

I originally encountered the issue via a cryptic error message in SourceTree. Running git gc on the command line helped me narrow down the issue:

> git gc
fatal: bad object refs/heads/1.2 2
fatal: failed to run repack
Run Code Online (Sandbox Code Playgroud)

I was able to fix the issue by removing the " 2" suffix:

> mv .git/refs/heads/1.2\ 2 .git/refs/heads/1.2
Run Code Online (Sandbox Code Playgroud)

  • 也为我工作,谢谢!我使用的是 Mac,所以我按 cmd+shift+period 来显示隐藏文件,然后导航到目录中隐藏的 .git 文件夹,向下钻取,并删除我的目录中令人讨厌的“(1)”后缀。问题文件。是的,我认为 Google Drive 也适用于我的情况。 (9认同)
  • 是的,为我工作。我认为在我的例子中是 Google Drive。谢谢你! (4认同)

MoS*_*lam 11

在这里详细说明@Robin的答案对我有用:

首先查看origin目录的内容

ls -l .git/refs/remotes/origin
Run Code Online (Sandbox Code Playgroud)

结果是头头2..

所以,我所做的是HEAD 2使用删除重复文件

rm '.git/refs/remotes/origin/HEAD 2'
Run Code Online (Sandbox Code Playgroud)

然后我使用获取远程分支

git fetch
Run Code Online (Sandbox Code Playgroud)

然后设置本地分支来跟踪远程分支

git branch --set-upstream-to=origin/{YOUR_REMOTE_BRANCH}
Run Code Online (Sandbox Code Playgroud)

就是这样。