在Angular 8中,如果你要更新仓库,却发现仓库不干净,请先提交或保存任何更改。

168

错误

仓库不干净。在更新之前,请提交或存储任何更改

当我从版本7更新到Angular 8时出现此问题。

Angular升级指南https://update.angular.io/#7.0:8.0

  D:\app-test> ng update @angular/cli @angular/core
               npm cache verify

代码库不干净。在更新前,请提交或隐藏任何更改。

更新版本

    PS D:\app-test> ng update
                Using package manager: 'npm'
                Collecting installed dependencies...
                Found 58 dependencies.
                    We analyzed your package.json, there are some packages to update:

                      Name                               Version                  Command to update
                     --------------------------------------------------------------------------------
                      @angular/cdk                       7.2.2 -> 8.0.1           ng update @angular/cdk
                      @angular/core                      7.2.15 -> 8.0.1          ng update @angular/core
                      @angular/core                      7.2.2 -> 7.2.15          ng update @angular/core
                      @angular/material                  7.3.7 -> 8.0.1           ng update @angular/material
                      rxjs                               6.3.3 -> 6.5.2           ng update rxjs


                    There might be additional packages that are outdated.
                    Run "ng update --all" to try to update all at the same time.

                PS D:\app-test> ng update @angular/cdk
                Repository is not clean.  Please commit or stash any changes before updating.

我已经检查了项目,发现未安装Git。

解决方案:

   git commit 

在谷歌上搜索后,我发现这种情况发生在Angular 8之后。

问题

https://github.com/angular/angular-cli/issues/14600


这是 Angular 8 中的一个 bug。https://github.com/angular/angular-cli/issues/14600 - afeef
10个回答

318

这是 Angular 8 的一个 bug。

你可以通过使用以下命令进行解决:

ng update @angular/cli @angular/core --allow-dirty


6
这并没有起作用,出现了错误“存储库不干净。更新更改将与预先存在的更改混合。 使用软件包管理器:'npm' 收集已安装的依赖项... 找到0个依赖项。 软件包'@angular/cli'不是一个依赖项。” - Shilpi Jaiswal
2
无法工作,出现错误“存储库不存在...”。 - Finn
6
这不是一个错误,而是一种有意的功能。当命令行界面意外更新了本不该更新的文件时,这种功能就会生效,避免可能会导致应用程序崩溃的情况发生。 - Edric
2
@Edric 当它像我一样(v8.2)发出错误信息时,这是一个bug。 - qu1j0t3
ng update @angular/cli @angular/core --allow-dirty gives me the error: Package '@angular/cli' is not a dependency. - Adam Norton
显示剩余5条评论

76

我尝试使用提及命令将Angular 8升级到Angular 9,但仍然遇到错误。

然后我尝试了同样的命令,使用--force标志,并且它对我起作用了。

ng update @angular/cli @angular/core --allow-dirty --force

55

我也遇到过同样的问题。这是 Angular 8 中的一个常见错误。如果你真的需要绕过仓库检查,可以使用脏命令来实现,例如:

(如果你真的需要绕过,请遵循强制命令)

ng update @angular/cli @angular/core --allow-dirty or
ng update @angular/cli @angular/core --allow-dirty --force

但是,我没有那样做。我按照以下步骤进行...

首先,仔细检查是否在更新之前提交了所有更改。然后将项目副本保存到同一位置并将副本也提交到Git。接下来从原始项目目录运行以下命令。

ng update @angular/core@8 @angular/cli@8

接下来,您可以删除副本。这对我有用!谢谢!


12

对我来说起作用了

sudo npm update @angular/cli @angular/core --allow-dirty --legacy-peer-deps

1
其他的方法都没用,但这个可以!!2022年5月 - Adam Norton

5
以下内容适用于我将Angular 13项目升级到Angular 14(2022年10月)的操作:
在您的项目目录中,以管理员权限打开命令提示符。然后运行以下命令:
ng update @angular/core@14 @angular/cli@14 --allow-dirty --force 这将显示类似于以下输出(根据您现有的Angular版本可能会有所不同):
The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 14.2.5 to perform the update.
√ Package successfully installed.
Repository is not clean. Update changes will be mixed with pre-existing changes.
Using package manager: npm
Collecting installed dependencies...
Found 23 dependencies.
Fetching dependency metadata from registry...
    Updating package.json with dependency @angular-devkit/build-angular @ "14.2.5" (was "13.2.6")...
    Updating package.json with dependency @angular/cli @ "14.2.5" (was "13.2.6")...
    Updating package.json with dependency @angular/compiler-cli @ "14.2.5" (was "13.2.7")...
    Updating package.json with dependency typescript @ "4.8.4" (was "4.5.5")...
    Updating package.json with dependency @angular/animations @ "14.2.5" (was "13.2.7")...
    Updating package.json with dependency @angular/common @ "14.2.5" (was "13.2.7")...
    Updating package.json with dependency @angular/compiler @ "14.2.5" (was "13.2.7")...
    Updating package.json with dependency @angular/core @ "14.2.5" (was "13.2.7")...
    Updating package.json with dependency @angular/forms @ "14.2.5" (was "13.2.7")...
    Updating package.json with dependency @angular/platform-browser @ "14.2.5" (was "13.2.7")...
    Updating package.json with dependency @angular/platform-browser-dynamic @ "14.2.5" (was "13.2.7")...
    Updating package.json with dependency @angular/router @ "14.2.5" (was "13.2.7")...
UPDATE package.json (1068 bytes)
√ Packages successfully installed.
** Executing migrations of package '@angular/cli' **

> Remove 'defaultProject' option from workspace configuration.
  The project to use will be determined from the current working directory.
UPDATE angular.json (3177 bytes)
  Migration completed.

> Remove 'showCircularDependencies' option from browser and server builders.
  Migration completed.

> Replace 'defaultCollection' option in workspace configuration with 'schematicCollections'.
  Migration completed.

> Update Angular packages 'dependencies' and 'devDependencies' version prefix to '^' instead of '~'.
UPDATE package.json (1068 bytes)
√ Packages installed successfully.
  Migration completed.

> Remove 'package.json' files from library projects secondary entrypoints.
  Migration completed.

> Update TypeScript compilation target to 'ES2020'.
UPDATE tsconfig.json (863 bytes)
  Migration completed.

** Executing migrations of package '@angular/core' **

> As of Angular version 13, `entryComponents` are no longer necessary.
  Migration completed.

> In Angular version 14, the `pathMatch` property of `Routes` was updated to be a strict union of the two valid options: `'full'|'prefix'`.
  `Routes` and `Route` variables need an explicit type so TypeScript does not infer the property as the looser `string`.
  Migration completed.

> As of Angular version 14, Forms model classes accept a type parameter, and existing usages must be opted out to preserve backwards-compatibility.
  Migration completed.

以下是我升级后的 package.json 文件更新内容:
{
  "name": "custom-project-14",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^14.2.5",
    "@angular/common": "^14.2.5",
    "@angular/compiler": "^14.2.5",
    "@angular/core": "^14.2.5",
    "@angular/forms": "^14.2.5",
    "@angular/platform-browser": "^14.2.5",
    "@angular/platform-browser-dynamic": "^14.2.5",
    "@angular/router": "^14.2.5",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.2.5",
    "@angular/cli": "^14.2.5",
    "@angular/compiler-cli": "^14.2.5",
    "@types/jasmine": "~3.10.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~4.0.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.1.0",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.8.4"
  }
}

升级从13到14时,我也遇到了这个问题。 - undefined

1
在我的情况下,这是因为 node_modules 文件夹没有被 .gitignore 排除导致的。添加后,此错误不再出现。

1

我在各处询问,最终得到了这个建议,并且它对我起作用了。我从AIs和指南网站收集了以下信息:

错误消息“Repository is not clean. Please commit or stash any changes before updating”表示您的Git存储库中有未提交的更改,需要在更新Angular之前将其提交或隐藏。

要解决此问题,您可以按照以下步骤操作:

打开终端并导航到您的Angular项目目录。

在终端中运行此命令:

git status

以查看您的Git存储库的状态。

如果有任何未提交的更改,您可以通过运行以下命令之一来提交它们:

git commit -m "commit message"

或者通过运行以下命令来隐藏它们:

git stash

提交或隐藏更改后,请再次运行以下命令:

ng update @angular/core @angular/cli

以更新Angular。

更新完成后,您可以通过运行以下命令将更改应用于更新后的代码:

git stash apply

如果您已经将更改存储,或者如果您已经提交了更改,则可以通过手动合并更改来解决。

另外,请注意:在更新项目中的任何依赖项之前,始终最好先提交您的更改。这样可以确保在更新过程中出现任何问题时,您都有代码备份。


0

这种情况可能会出现。只需提交或存储任何更改,然后再次运行命令即可。


0

这很简单。只需要提交它。

git add .
git commit -m "wip:before updating"

Angular只是希望您在更新之前最小化地“备份”您的工作。这只是一个好习惯。


0

首先,检查一下你的代码是否有未推送到Git的更改,如果有,请将它们推送。然后关闭旧的cmd实例并打开一个新的cmd实例,然后运行命令。 这对我起作用了,谢谢。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接