Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upgrade flutter if I have local changes in my FlutterRoot folder?

Tags:

flutter

I'am getting an error when I run flutter upgrade command. Upgrading Flutter from E:\flutter... Updating f37c235c3..5391447fa error: Your local changes to the following files would be overwritten by merge: packages/flutter_tools/gradle/flutter.gradle Please commit your changes or stash them before you merge. Aborting

like image 260
Aryan Khera Avatar asked Dec 24 '18 23:12

Aryan Khera


1 Answers

It's because you have made some changes in this file:

<FlutterRoot>/packages/flutter_tools/gradle/flutter.gradle

that's the root directory of flutter, where there is also the bin folder.

Maybe you have made such modifications in order to have some gradle rules to be spreaded to all your flutter projects, I don't know, you should know ;-]

When we have flutter root path that has some modifications made by us (either because we need it or unintended) when we try to update flutter or change flutter channel we get an error.

In this cases we have two paths to choose:

Go to <FlutterRoot> and

  1. Discard changes with a git checkout . (or stash them if you now what that means) .

Discarding changes is a destructive action, so you should backup or at least know if these are wanted and useful modifications so that you can add them again after and update or a change of channel

Today there's also a section in the flutter github official repo wiki to address this scenario:

Workarounds-for-common-issues

Here you can find this solution

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

The first command remove all untrack repo files (for example if you add a file of yours) and the third line drop your previous stash.

So this is a destructive command like git checkout . but it also clean all files that don't belong to the standard flutter repo.

If haven't intended modification on your flutter root project forlder you could choose either git checkout . or the above bunch of commands.

But if you had modification that you need to preserve, you can choose the following solution or stash this modification but not drop this stash, otherwise you will loose it.

  1. Commit your changes with git add . && git commit -m "my changes whatever" and see if flutter update can merge the flutter official changes with yours.

If you don't remember where <FlutterRoot> is you could type:

  • OSX/Linux: which flutter
  • Windows: where flutter

This should print <FlutterRoot>/bin/flutter.

like image 166
shadowsheep Avatar answered Oct 23 '22 04:10

shadowsheep