You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac执行flutter upgrade报错,急求快速解决方案

解决Mac上flutter upgrade时Git引用损坏的错误

错误场景

执行flutter upgrade时出现Git引用损坏/IO错误,具体报错:

adedoyinolanipekun@ADEDOYINs-MacBook-Pro momaspay % flutter upgrade   
ProcessException: Process exited abnormally:
error: cannot lock ref 'refs/tags/2.8.0-3.3.pre': unable to resolve reference 'refs/tags/2.8.0-3.3.pre': Input/output error
From https://github.com/flutter/flutter
 ! [new tag]               2.8.0-3.3.pre -> 2.8.0-3.3.pre  (unable to update local ref)
error: cannot lock ref 'refs/tags/2.8.1': unable to resolve reference 'refs/tags/2.8.1': reference broken
 ! [new tag]               2.8.1         -> 2.8.1  (unable to update local ref)
error: cannot lock ref 'refs/tags/2.9.0-0.0.pre': unable to resolve reference 'refs/tags/2.9.0-0.0.pre': reference broken
 ! [new tag]               2.9.0-0.0.pre -> 2.9.0-0.0.pre  (unable to update local ref)
  Command: git fetch --tags

解决方案

步骤1:进入Flutter SDK目录

默认安装路径是~/flutter,执行:

cd ~/flutter

如果你的Flutter安装在其他路径,替换成对应路径即可。

步骤2:删除损坏的本地Tag引用

直接删除报错的tag:

git tag -d 2.8.0-3.3.pre 2.8.1 2.9.0-0.0.pre

如果不确定所有损坏的tag,也可以先执行git fsck --full列出所有损坏的引用,再针对性删除。

步骤3:清理Git缓存与无用对象

git gc --prune=now
git reset --hard HEAD

步骤4:强制拉取最新Tag并重新升级

git fetch --tags --force
flutter upgrade

终极方案(以上方法无效时)

如果上述操作都无法解决,直接重新克隆Flutter SDK:

  1. 备份原Flutter目录(如果有自定义配置)
  2. 删除原目录:rm -rf ~/flutter
  3. 重新克隆:git clone https://github.com/flutter/flutter.git
  4. 确保环境变量配置正确(若之前已配置可跳过)

内容的提问来源于stack exchange,提问作者abeeb ilias

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 07:22:37