【问题标题】:How to solve a Flutter problem - fatal: not a git repository如何解决 Flutter 问题 - 致命:不是 git 存储库
【发布时间】:2021-08-02 13:15:14
【问题描述】:

我是 Flutter/Dart/Git 的新手,几周以来我一直被困在一个地方。我已经在其他几台机器上使用 Flutter/Android Studio 做了一些简单的项目,这个问题不存在。它工作正常。我想在我的主计算机上使用这个软件而不使用远程桌面...我的操作系统是 Windows 10。

每次我点击任何颤振命令时都会收到相同的错误:

fatal: not a git repository (or any of the parent directories): .git
Building flutter tool...
Running pub upgrade...

以下解决方案对我不起作用:

  • 删除 ./pub-cache 文件夹,修复 pub 缓存
  • git 初始化/git 克隆
  • 扑干净
  • flutter create --sample=material.AppBar.1 mysample
  • 从其他计算机复​​制工作项目
  • 从项目目录运行命令,例如。 C:\Users\User\AndroidStudioProjects\MyProject\
  • 重新安装我使用的所有东西:Flutter、Android Studio、Git
  • 禁用防病毒/从隔离区中删除颤振文件
  • 可能还有其他一些

2021 年 5 月 18 日编辑

我发现在我的主机上一切正常,但在登录其他 Windows 用户帐户后。所以我的用户设置可能有问题。 我试图删除我的用户目录 C:\Users\User 中与 dart/flutter/android 相关的所有内容。之后我删除了 F:\src 目录,再次卸载了 git,克隆了颤振。不幸的是,错误仍然发生...我不知道我还能做什么... 它看起来只是配置文件中的一个简单更改,但是哪个?

Git 命令看起来可以正常工作,例如

C:\>git --version
git version 2.30.1.windows.1

Git 状态

F:\src\flutter>git status
On branch stable
Your branch is up to date with 'origin/stable'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .knownPackages
        .pub-cache_old/
        .temp/
        build-tools/
        emulator/
        licenses/
        patcher/
        platform-tools/
        platforms/
        sdk/
        skins/
        sources/
        system-images/
        tools/

nothing added to commit but untracked files present (use "git add" to track)

一切都是最新的,例如颤抖:

C:\>flutter upgrade --force
fatal: not a git repository (or any of the parent directories): .git
Building flutter tool...
Running pub upgrade...
Upgrading Flutter to 2.0.6 from 2.0.1 in F:\src\flutter...
fatal: not a git repository (or any of the parent directories): .git
Checking Dart SDK version...
Downloading Dart SDK from Flutter engine 05e680e202af9a92461070cb2d9982acad46c83c...
Building flutter tool...
Running pub upgrade...

Upgrading engine...
fatal: not a git repository (or any of the parent directories): .git
Building flutter tool...
Running pub upgrade...
Downloading android-arm-profile/windows-x64 tools...             2 699ms
Downloading android-arm-release/windows-x64 tools...             1 329ms
Downloading android-arm64-profile/windows-x64 tools...           1 476ms
Downloading android-arm64-release/windows-x64 tools...           1 992ms
Downloading android-x64-profile/windows-x64 tools...             1 517ms
Downloading android-x64-release/windows-x64 tools...             1 096ms
Downloading android-x86 tools...                                   16,9s
Downloading android-x64 tools...                                   16,9s
Downloading android-arm tools...                                    7,7s
Downloading android-arm-profile tools...                            3,9s
Downloading android-arm-release tools...                            3,3s
Downloading android-arm64 tools...                                  8,3s
Downloading android-arm64-profile tools...                          4,0s
Downloading android-arm64-release tools...                          3,5s
Downloading android-x64-profile tools...                            5,0s
Downloading android-x64-release tools...                            3,8s
Downloading android-x86-jit-release tools...                        5,6s
Downloading Web SDK...                                             18,8s

Flutter 2.0.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 1d9032c7e1 (12 days ago) • 2021-04-29 17:37:58 -0700
Engine • revision 05e680e202
Tools • Dart 2.12.3

Running flutter doctor...
fatal: not a git repository (or any of the parent directories): .git
Building flutter tool...
Running pub upgrade...
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.6, on Microsoft Windows [Version 10.0.19042.928], locale pl-PL)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] Connected device (3 available)

! Doctor found issues in 1 category.

颤振医生-vv:

F:\src\flutter>flutter doctor -vv
fatal: not a git repository (or any of the parent directories): .git
Building flutter tool...
Running pub upgrade...
[ +111 ms] executing: [F:\src\flutter/] git -c log.showSignature=false log -n 1
--pretty=format:%H
[ +107 ms] Exit code 0 from: git -c log.showSignature=false log -n 1
--pretty=format:%H
[   +1 ms] a5cdb02597b2f35c484238501982a987f7c70c60
[   +1 ms] executing: [F:\src\flutter/] git tag --points-at
a5cdb02597b2f35c484238501982a987f7c70c60
[  +74 ms] Exit code 0 from: git tag --points-at
a5cdb02597b2f35c484238501982a987f7c70c60
[   +2 ms] executing: [F:\src\flutter/] git describe --match *.*.* --long --tags
a5cdb02597b2f35c484238501982a987f7c70c60
[ +100 ms] Exit code 0 from: git describe --match *.*.* --long --tags
a5cdb02597b2f35c484238501982a987f7c70c60
[   +1 ms] 2.0.6-1-ga5cdb02597
[  +66 ms] executing: [F:\src\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +67 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [F:\src\flutter/] git ls-remote --get-url origin
[  +58 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[ +104 ms] executing: [F:\src\flutter/] git rev-parse --abbrev-ref HEAD
[  +73 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[ +102 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required,
skipping update.
[   +2 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required,
skipping update.
[   +2 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping
update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +5 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping
update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping
update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping
update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required,
skipping update.
[   +1 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required,
skipping update.
[   +1 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required,
skipping update.
[   +1 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required,
skipping update.
[  +70 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[   +1 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required,
skipping update.
[   +1 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required,
skipping update.
[   +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping
update.
[   +1 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping
update.
[   +1 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping
update.
[   +1 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping
update.
[   +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required,
skipping update.
[   +1 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required,
skipping update.
[   +1 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required,
skipping update.
[   +1 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required,
skipping update.
[   +1 ms] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[   +3 ms] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping
update.
[   +1 ms] Artifact Instance of 'PubDependencies' is not required, skipping update.
[  +23 ms] executing: [F:\src\flutter/] git rev-parse --abbrev-ref HEAD
[  +67 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[   +1 ms] stable
[   +1 ms] Skipping request to fetchTags - on well known channel stable.
[        ] executing: [F:\src\flutter/] git tag --points-at HEAD
[  +71 ms] Exit code 0 from: git tag --points-at HEAD
[   +1 ms] executing: [F:\src\flutter/] git describe --match *.*.* --long --tags
HEAD
[  +85 ms] Exit code 0 from: git describe --match *.*.* --long --tags HEAD
[   +1 ms] 2.0.6-1-ga5cdb02597
[  +12 ms] executing: C:\Program Files\Android\Android Studio\jre\bin\java -version
[ +183 ms] Exit code 0 from: C:\Program Files\Android\Android Studio\jre\bin\java
-version
[   +2 ms] openjdk version "11.0.8" 2020-07-14
           OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
           OpenJDK 64-Bit Server VM (build 11.0.8+10-b944.6842174, mixed mode)
[  +12 ms] executing: C:\Program Files\Android\Android Studio\jre\bin\java -version
[ +187 ms] Exit code 0 from: C:\Program Files\Android\Android Studio\jre\bin\java
-version
[   +2 ms] openjdk version "11.0.8" 2020-07-14
           OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
           OpenJDK 64-Bit Server VM (build 11.0.8+10-b944.6842174, mixed mode)
[  +20 ms] executing: [F:\src\flutter/] git -c log.showSignature=false log -n 1
--pretty=format:%ar
[  +62 ms] Exit code 0 from: git -c log.showSignature=false log -n 1
--pretty=format:%ar
[   +1 ms] 26 minutes ago
[  +77 ms] java -version
[  +25 ms] executing: F:\src\flutter\platform-tools\adb.exe devices -l
[  +34 ms] [√] Flutter (Channel stable, 2.0.7-0.0.pre.1, on Microsoft Windows
[Version
               10.0.19042.928], locale pl-PL)
[   +4 ms]     • Flutter version 2.0.7-0.0.pre.1 at F:\src\flutter
[   +2 ms]     • Framework revision a5cdb02597 (26 minutes ago), 2021-05-14
15:23:36 +0200
[   +1 ms]     • Engine revision 05e680e202
[   +1 ms]     • Dart version 2.12.3
|[ +131 ms] List of devices attached
/[ +134 ms] executing: F:\src\flutter\platform-tools\adb.exe devices -l
-[  +71 ms] List of devices attached
[+5681 ms] [√] Android toolchain - develop for Android devices (Android SDK version
30.0.3)
[   +2 ms]     • Android SDK at F:\src\flutter
[   +1 ms]     • Platform android-30, build-tools 30.0.3
[   +1 ms]     • Java binary at: C:\Program Files\Android\Android
Studio\jre\bin\java
[   +1 ms]     • Java version OpenJDK Runtime Environment (build
11.0.8+10-b944.6842174)
[   +1 ms]     • All Android licenses accepted.
[   +3 ms] [√] Chrome - develop for the web
[   +1 ms]     • Chrome at C:\Program Files
(x86)\Google\Chrome\Application\chrome.exe
[   +3 ms] [√] Android Studio (version 4.1.0)
[   +1 ms]     • Android Studio at C:\Program Files\Android\Android Studio
[   +3 ms]     • Flutter plugin can be installed from:
[        ]        https://plugins.jetbrains.com/plugin/9212-flutter
[        ]     • Dart plugin can be installed from:
[        ]        https://plugins.jetbrains.com/plugin/6351-dart
[   +1 ms]     • Java version OpenJDK Runtime Environment (build
11.0.8+10-b944.6842174)
[   +2 ms] [√] Connected device (2 available)
[   +1 ms]     • Chrome (web) • chrome • web-javascript • Google Chrome
90.0.4430.212
[   +1 ms]     • Edge (web)   • edge   • web-javascript • Microsoft Edge
90.0.818.56
[   +1 ms] • No issues found!
[  +15 ms] "flutter doctor" took 7 075ms.
[ +160 ms] ensureAnalyticsSent: 154ms
[   +3 ms] Running shutdown hooks
[   +1 ms] Shutdown hooks complete
[   +1 ms] exiting with code 0

如果有人能指导我解决我的问题,我会很高兴。我希望这是一件小事,但我无法处理。 问候

2021 年 5 月 15 日编辑

我提供了 C:\ 目录中预期的 pubspec.yaml 文件的其他错误,这可能有助于解决此问题:

f:\test>flutter create --sample=material.AppBar.1 mysample
fatal: not a git repository (or any of the parent directories): .git
Building flutter tool...
Running pub upgrade...
Creating project mysample...
  mysample\.gitignore (created)
  mysample\.idea\libraries\Dart_SDK.xml (created)
  mysample\.idea\libraries\KotlinJavaRuntime.xml (created)
  mysample\.idea\modules.xml (created)
  mysample\.idea\runConfigurations\main_dart.xml (created)
  mysample\.idea\workspace.xml (created)
  mysample\.metadata (created)
  mysample\android\app\build.gradle (created)
  mysample\android\app\src\main\kotlin\com\example\mysample\MainActivity.kt (created)
  mysample\android\build.gradle (created)
  mysample\android\mysample_android.iml (created)
  mysample\android\.gitignore (created)
  mysample\android\app\src\debug\AndroidManifest.xml (created)
  mysample\android\app\src\main\AndroidManifest.xml (created)
  mysample\android\app\src\main\res\drawable\launch_background.xml (created)
  mysample\android\app\src\main\res\drawable-v21\launch_background.xml (created)
  mysample\android\app\src\main\res\mipmap-hdpi\ic_launcher.png (created)
  mysample\android\app\src\main\res\mipmap-mdpi\ic_launcher.png (created)
  mysample\android\app\src\main\res\mipmap-xhdpi\ic_launcher.png (created)
  mysample\android\app\src\main\res\mipmap-xxhdpi\ic_launcher.png (created)
  mysample\android\app\src\main\res\mipmap-xxxhdpi\ic_launcher.png (created)
  mysample\android\app\src\main\res\values\styles.xml (created)
  mysample\android\app\src\main\res\values-night\styles.xml (created)
  mysample\android\app\src\profile\AndroidManifest.xml (created)
  mysample\android\gradle\wrapper\gradle-wrapper.properties (created)
  mysample\android\gradle.properties (created)
  mysample\android\settings.gradle (created)
  mysample\ios\Runner\AppDelegate.swift (created)
  mysample\ios\Runner\Runner-Bridging-Header.h (created)
  mysample\ios\Runner.xcodeproj\project.pbxproj (created)
  mysample\ios\Runner.xcodeproj\xcshareddata\xcschemes\Runner.xcscheme (created)
  mysample\ios\.gitignore (created)
  mysample\ios\Flutter\AppFrameworkInfo.plist (created)
  mysample\ios\Flutter\Debug.xcconfig (created)
  mysample\ios\Flutter\Release.xcconfig (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Contents.json (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-1024x1024@1x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-20x20@1x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-20x20@2x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-20x20@3x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-29x29@1x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-29x29@2x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-29x29@3x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-40x40@1x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-40x40@2x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-40x40@3x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-60x60@2x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-60x60@3x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-76x76@1x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-76x76@2x.png (created)
  mysample\ios\Runner\Assets.xcassets\AppIcon.appiconset\Icon-App-83.5x83.5@2x.png (created)
  mysample\ios\Runner\Assets.xcassets\LaunchImage.imageset\Contents.json (created)
  mysample\ios\Runner\Assets.xcassets\LaunchImage.imageset\LaunchImage.png (created)
  mysample\ios\Runner\Assets.xcassets\LaunchImage.imageset\LaunchImage@2x.png (created)
  mysample\ios\Runner\Assets.xcassets\LaunchImage.imageset\LaunchImage@3x.png (created)
  mysample\ios\Runner\Assets.xcassets\LaunchImage.imageset\README.md (created)
  mysample\ios\Runner\Base.lproj\LaunchScreen.storyboard (created)
  mysample\ios\Runner\Base.lproj\Main.storyboard (created)
  mysample\ios\Runner\Info.plist (created)
  mysample\ios\Runner.xcodeproj\project.xcworkspace\contents.xcworkspacedata (created)
  mysample\ios\Runner.xcodeproj\project.xcworkspace\xcshareddata\IDEWorkspaceChecks.plist (created)
  mysample\ios\Runner.xcodeproj\project.xcworkspace\xcshareddata\WorkspaceSettings.xcsettings (created)
  mysample\ios\Runner.xcworkspace\contents.xcworkspacedata (created)
  mysample\ios\Runner.xcworkspace\xcshareddata\IDEWorkspaceChecks.plist (created)
  mysample\ios\Runner.xcworkspace\xcshareddata\WorkspaceSettings.xcsettings (created)
  mysample\lib\main.dart (created)
  mysample\mysample.iml (created)
  mysample\pubspec.yaml (created)
  mysample\README.md (created)
  mysample\test\widget_test.dart (created)
  mysample\web\favicon.png (created)
  mysample\web\icons\Icon-192.png (created)
  mysample\web\icons\Icon-512.png (created)
  mysample\web\index.html (created)
  mysample\web\manifest.json (created)
Could not find a file named "pubspec.yaml" in "C:\".
Running "flutter pub get" in mysample...
pub get failed (66; Could not find a file named "pubspec.yaml" in "C:\".)

【问题讨论】:

    标签: git flutter android-studio


    【解决方案1】:

    我也有同样的问题。我修改了我的命令提示符设置...我想让我的命令提示符在特定目录中自动打开,所以我在我的注册表中添加了一个自动运行选项。这实际上导致了您在此处看到的相同错误。您的环境中是否有类似的东西导致命令在错误的目录中运行?作为参考,我不得不从路径 HKEY_CURRENT_USER\Software\Microsoft\Command Processor 中删除密钥 AutoRun,这解决了我的颤振问题。

    【讨论】:

    • 这就是重点!现在一切正常。非常感谢:)
    • 我的问题解决了!
    【解决方案2】:

    您使用 zip 链接而不是 git clone 下载了 Flutter。至少我认为那条消息是这样的

    尝试进入文件夹:

    cd F:\src\flutter
    

    然后执行下一条命令

    git status
    

    当我对非来自 github 的文件夹执行相同操作时,可能会出现与我相同的错误

    可能你下载了一个固定的SDK,教程中解释了它:https://flutter.dev/docs/get-started/install/windows

    如果不想安装固定版本的安装 捆绑包,您可以跳过步骤 1 和 2。相反,从 GitHub 上的 Flutter 存储库,并根据需要更改分支或标签。为了 例子: C:\src&gt;git clone https://github.com/flutter/flutter.git -b stable

    这就是我在 Flutter 文件夹中执行 git status 时所拥有的

    显然我没有对 Flutter 进行 100% 升级,因为我正在处理生产中的项目。

    btw:我用的是mac,所以我的终端很不一样,但是思路是一样的

    无论如何

    flutter clean
    flutter --version
    flutter pub get
    flutter run
    ....
    

    应该可以工作,但不是flutter --upgrade,因为需要连接到git项目并下载最后一个稳定版本

    【讨论】:

    • 您好丹妮,谢谢您的回复。是的,我从flutter.dev/docs/get-started/install/windows 安装了颤振,但是 git status 命令没有给出错误。所以我还在寻找答案。
    • 你有正确的路径吗?我的意思是,flutter 命令指向的是flutter sdk?
    • 你可能会问我的环境变量。删除路径变量中的条目 (F:\src\flutter\bin) 后,我收到预期的错误 C:\>flutter 'flutter' is not known as an internal or external command, operable program or batch file。所以flutter命令指向flutter sdk
    • C:\>flutter F:\src\flutter\bin\flutter F:\src\flutter\bin\flutter.bat
    • 我在 C:\ 目录中的 pubspec.yaml 文件中添加了一个错误(flutter create 命令)
    【解决方案3】:

    按照以下步骤解决:

    1. 重启电脑。
    2. 删除 C:/src/flutter。
    3. 打开 Android Studio。然后转到 VCS > 从版本控制中获取
    4. 将此粘贴​​到 URL:https://github.com/flutter/flutter.git
    5. 设置目录 C:\src\flutter
    6. 点击克隆
    7. 重启 Android Studio。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-11
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多