几个月没有在某个静态网站上工作后,我回来尝试从 GitHub 存储库中提取更改。
\n发生以下fatal: bad object refs/heads 2/master
错误。
(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我试图阻止删除本地副本并重新克隆存储库,因为我不想丢失本地更改。还有其他想法吗?
\nRob*_*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)
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)
就是这样。