9

I recently decided to run flutter upgrade, but after starting, the command terminal states:

Your flutter checkout has local changes that would be erased by upgrading. If you want to keep these changes, it is recommended that you stash them via "git stash" or else commit the changes to a local branch. If it is okay to remove local changes, then re-run this command with "--force".

I don't know what it means by "local changes." I'm not very familiar with git and do not generally need to mess with it explicitly. I'm concerned that I'm going to mess something up if use "--force."

Is there a way I can check what these changes are/were first? It's probably some local configuration change that I forgot about.

Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
  • seems like you edited some source code. do force update if you dont care about it – Md. Yeasin Sheikh Aug 16 '22 at 22:27
  • 1
    Consider running `git diff HEAD` to compare the current checkout files against the current commit, or just `git diff` (no additional flags or options) to compare them against the current index. If you haven't been doing Git-ish things, these will produce the same output. Either way you'll get to see what changes you made. – torek Aug 17 '22 at 08:47

4 Answers4

8

You probably changed flutter source code either intentionally or accidentally. The message simply states that if you wanted to keep those changes you have done previously, you have to use git stash (Stash the changes in a dirty working directory away) command to temporary save your work and after upgrade you can re apply saved work at flutter source code.

Usually flutter upgrade --force in this situation.

Usama Karim
  • 1,100
  • 4
  • 15
6

A slightly more complete answer, so that you can see what changes have actually been made to your local flutter environment:

cd ~/development/flutter #or wherever you installed flutter
git diff HEAD

In my case, git reminded me that I had added '--disable-web-security' to packages/flutter_tools/lib/src/web/chrome.dart which is what I suspect will be a very common local change.

git stash #if you like, or just remember your changes
flutter upgrade --force #to upgrade flutter

Now you can put your local changes back, assuming you still want them.

2
git stash

flutter upgrade --force

it solved my problem

0

You should never ever do destructive changes without knowing exactly why you're doing them, and what the downsides are. Blindly doing flutter upgrade --force is just not got practice and bad advice IMHO, even if the results work out.

Instead, make sure you aren't running the flutter upgrade from your local project directory. You should be running it from your flutter directory (e.g. # cd flutter_path/). To begin with, your local directory likely has Flutter related details in .gitignore, meaning your local project won't be committing the following to git (on default settings):

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

As such, even git stash from your local directory won't be seen by Flutter with the above configuration...

Tl;dr: a very easy and "safe" practice is to cd to your root Flutter folder and run the upgrade there. You can commit/stash your local Flutter packages changes, etc. from there and then run the flutter upgrade command safely after that with peace of mind. That's better practice. Ofc, if you know exactly what you're doing and why, then do what's best for you (but you don't need this advice anyway)...

Oprimus
  • 1,652
  • 3
  • 11
  • 20