【问题标题】:'submodule' appears to be a git command, but we were not able to execute it'submodule' 似乎是一个 git 命令,但我们无法执行它
【发布时间】:2021-08-14 15:50:49
【问题描述】:

我克隆了一个 git 存储库,它是一个 Angular 7 和 .NET Core 应用程序,项目中一切正常,但是当我尝试恢复 npm 包时,我收到以下错误。

\Microsoft\TeamFoundation\Team Explorer\Git\cmd\git.EXE 子模块 更新 -q --init --recursive 致命的:“子模块”似乎是一个 git 命令,但我们不是 能够执行它。也许 git-submodule 坏了? 在 ChildProcess.exithandler (child_process.js:291:12) 在 ChildProcess.emit (events.js:182:13) 在可能关闭(内部/child_process.js:961:16) 在 Process.ChildProcess._handle.onexit (internal/child_process.js:248:5) npm 错误! cb() 从未调用过!

#Package.json

{
 "name": "name",
 "version": "6.1.1",
 "license": "......",
 "scripts": {
   "ng": "ng",
   "start": "ng serve --open",
   "start-hmr": "ng serve --configuration hmr -sm=false",
   "start-hmr-sourcemaps": "ng serve --hmr -e=hmr",
   "build": "node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng build --dev",
   "build-stats": "node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng build --dev --stats-json",
   "build-prod": "node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng build --prod",
   "build-prod-stats": "node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng build --prod --stats-json",
   "test": "ng test",
   "lint": "ng lint",
   "e2e": "ng e2e",
   "bundle-report": "webpack-bundle-analyzer dist/stats.json"
},
"private": true,
"dependencies": {
  "@agm/core": "1.0.0-beta.3",
  "@angular/animations": "6.0.5",
  "@angular/cdk": "6.2.1",
  "@angular/common": "6.0.5",
  "@angular/compiler": "6.0.5",
  "@angular/core": "6.0.5" 
},
"devDependencies": {
  "@angular-devkit/build-angular": "0.6.8",
  "@angular/cli": "6.0.8",
  "@angular/compiler-cli": "6.0.5",
  "@angular/language-service": "6.0.5",
  "@angularclass/hmr": "2.1.3",  
  "typescript": "2.7.2",
  "webpack-bundle-analyzer": "2.13.1"
  }
}

我安装的node-version 是10.7.0 和npm-version 是6.4.1

我在 GitHub 上发现了一些类似的问题,他们在 npm-lifecycle 中添加了一个修复程序,所以我安装了 npm-lifecycle,但我仍然遇到同样的错误。

【问题讨论】:

  • 我不知道是不是问题,但是在您粘贴的命令中,'-q' 选项内有一个空格

标签: node.js git visual-studio npm npm-install


【解决方案1】:

submodule 命令没有内置到基本的git.exe 二进制文件中,它是作为一个名为git-submodule 的shell 脚本实现的,它需要可以从%PATH% 访问,并且对于执行以下操作的用户是可执行的运行动作。

  • 你的 %PATH% 是什么(或你的 npm 进程的 %PATH%)?
  • 它是否包含您的 git 安装路径,它似乎在 \Microsoft\TeamFoundation\Team Explorer\Git\ 中的某个位置?
  • 运行npm进程的用户对git-submodule有执行权吗?

【讨论】:

  • 查看您的 PATH 环境变量:echo %PATH%
  • 在 Windows 上,您应该指向“bin”子文件夹。例如,就我而言,它是“C:\Program Files\Git\bin”
【解决方案2】:

Git 2.24(2019 年第四季度)将修复此错误消息的可能原因,在 Windows 上可以看到。

参见Adam Roben (aroben) 的commit 4e1a641(2019 年 8 月 24 日)。
(由 Junio C Hamano -- gitster -- 合并于 commit 6f21347,2019 年 9 月 30 日)

mingw: 修复从 Unicode 路径启动外部组件

如果 Git 安装在包含非 ASCII 字符的路径中, git am 和 git submodule 等命令,实现为 externals,将无法启动并出现以下错误:

fatal: 'am' appears to be a git command, but we were not able to execute it.  
Maybe git-am is broken?

这是由于 lookup_prog 不支持 Unicode。不知何故 错过了85faec9(Win32:Unicode 文件名支持(dirent 除外), 2012-03-15,Git v2.1.0-rc0)。

请注意,这个函数的唯一问题是调用 GetFileAttributes() 而不是 GetFileAttributesW()。
对access() 的调用很好,因为access() 是一个宏,它解析为 mingw_access(),它已经正确处理了 Unicode。
但是lookup_prog() 改为直接使用_waccess(),这样我们就只 将路径转换为 ​​UTF-16 一次。

为了使事情正常运行,我们必须在lookup_prog() 中同时维护 UTF-8 和 UTF-16 版本。

【讨论】:

    【解决方案3】:

    在我的情况下,在 Windows 10 上,除了 Windows 的 git 之外,似乎还调用了 cygin 的“git.exe”。将“C:\cygwin64\bin”移动到 PATH 的末尾以确保它位于“C”之后:\Program Files\Git\bin' 路径可以解决这个问题。

    【讨论】:

      【解决方案4】:

      您可能没有安装适用于 Windows 的 Git。我所做的,它似乎对我有用,是打开 Visual Studio 安装程序,然后选择“修改”当前安装并从“个人组件”选项卡中检查“Git for Windows”(未选中) .

      安装后我没有再遇到同样的错误。

      【讨论】:

      • 当然我安装了 Git,可能你没有很好地阅读问题,问题的前 6 个单词是我对你的回答的回答,实际上问题与路径有关。 :)
      猜你喜欢
      • 2015-12-09
      • 2015-05-24
      • 2022-12-11
      • 2012-08-13
      • 2013-05-10
      • 2018-10-04
      • 2018-07-13
      • 2023-01-12
      • 2010-11-12
      相关资源
      最近更新 更多