Update:
one reason you may want to ignore them from git commits is when you don't want them to be shown in pull requests which are being code reviewed. in this case you ignore generated files from git commit in your project.
TLDR:
if you add generated files to your git commits, and then hit any problems (which you rarely do) all you need to do is run build_runner
with the flag --delete-conflicting-outputs
flutter packages pub run build_runner build --delete-conflicting-outputs
Problems of adding generated files to Git commits And how to deal with them
the mentioned build_runner
documentation point on not adding generated files to your git commits is not a good point. which later i say why.
the point of adding generated files is not to be have to run build_runner each time you do a git pull or change branches since the source files have been changed or new source files have been added by your fellow developers and you need to run build_runner
to generate files for source files to be able to run the code without errors.
but what happens if you decide to add generated code to your git commits? and how can you easily solve them.
first problem is you might confront a merge conflict in a generated file. now how do you deal with this. you dont't. at this point you just resolve conflicts in the source file (if any) and then run build_runner and the gnerated files will be generated again.
the other problem is what mentioned in builder_runner
docs. which is when you run build_runner and it gives you this error
C:\workspace\flutter\projects> flutter pub run build_runner build
[INFO] Generating build script...
[INFO] Generating build script completed, took 336ms
[WARNING] Deleted previous snapshot due to missing asset graph.
[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 12.5s
[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 787ms
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Found 13 declared outputs which already exist on disk. This is likely because the`.dart_tool/build` folder was deleted, or you are submitting generated files to your source repository.
[SEVERE] Conflicting outputs were detected and the build is unable to prompt for permission to remove them. These outputs must be removed manually or the build can be run with `--delete-conflicting-outputs`. The outputs are: lib/models/advisory-service-item.g.dart
which you can easily solve buy adding --delete-conflicting-outputs
flag when running build_runner. like we do many times already
flutter packages pub run build_runner build --delete-conflicting-outputs
So for either problems you run the above command, that's it