Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to run `flutter upgrade`

Tags:

git

flutter

I am trying to both upgrade my Flutter SDK and also change my Flutter channel to master, but I encounter the following error:

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.

Why does this happen and how do fix this?

like image 622
Oto-obong Eshiett Avatar asked Jan 26 '19 18:01

Oto-obong Eshiett


2 Answers

These commands executed from the Flutter install directory should get you back to a working state

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

Now flutter upgrade, flutter channel ..., ... should work fine again.

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

like image 98
Günter Zöchbauer Avatar answered Sep 20 '22 00:09

Günter Zöchbauer


This occurs because the files have been changed locally. This means that the version you have on your machine is different from the one on GitHub.

The easiest way to fix this is using --force:

flutter upgrade --force

This will override any of the mismatched files. Make sure that you have no progress that would be lost by this (e.g. when you are working on a PR for flutter).


Another way of resolving this is to delete the files from your device and then execute flutter upgrade. This will resolve the Git error because it will just fetch the files from the internet again.

To do this head to your Flutter directory and remove the files. E.g. if your Flutter SDK directory was F:/data/flutter, you would need to remove the following files:

  • 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
like image 22
creativecreatorormaybenot Avatar answered Sep 19 '22 00:09

creativecreatorormaybenot