尝试运行“ flutter升级”或“ flutter更改频道”时出错

时间:2019-01-26 18:48:50

标签: git flutter

我正在尝试升级Flutter SDK,也将Flutter频道更改为master,但是遇到以下错误:

git: error: Your local changes to the following files would be overwritten by checkout:
git:    examples/catalog/android/build.gradle
git:    examples/catalog/android/gradle/wrapper/gradle-wrapper.properties
git:    packages/flutter_tools/gradle/flutter.gradle
git: Please commit your changes or stash them before you switch branches.
git: Aborting
Switching channels failed with error code 1.

为什么会发生这种情况以及如何解决?

2 个答案:

答案 0 :(得分:1)

之所以发生,是因为文件已在本地更改。这意味着您的计算机上的版本与GitHub上的版本不同。

解决此问题的最简单方法是从设备中删除文件,然后执行flutter upgrade。这将解决Git错误,因为它只会再次从Internet提取文件。

为此,请转到Flutter目录并删除文件。例如。如果您的Flutter SDK目录为F:/data/flutter,则需要删除以下文件:

  • F:/data/flutter/examples/catalog/android/build.gradle
  • F:/data/flutter/examples/catalog/android/gradle/wrapper/gradle-wrapper.properties
  • F:/data/flutter/packages/flutter_tools/gradle/flutter.gradle

答案 1 :(得分:1)

从Flutter安装目录执行的这些命令应使您回到工作状态

git clean -xfd
git stash save --keep-index
git stash drop
git pull
flutter doctor

现在flutter upgradeflutter channel ...,...应该可以正常工作。

https://github.com/flutter/flutter/wiki/Workarounds-for-common-issues#flutter-installation-corrupted