Repository is not clean. Please commit or stash any changes before updating In Angular 8
Asked Answered
H

10

174

Error

Repository is not clean. Please commit or stash any changes before updating

when i have updated from version 7 to Angular 8.

Angular Guide for upgrade https://update.angular.io/#7.0:8.0

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

Repository is not clean. Please commit or stash any changes before updating.

Update Version

    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.

i have checked git was not installed in project.

solution that worked

   git commit 

After Googling i have This is happening After Angular 8.

Bug

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

Hepplewhite answered 26/6, 2019 at 13:5 Comment(2)
this is bug in angular 8 github.com/angular/angular-cli/issues/14600Hepplewhite
Does this answer your question? ng update --all does say 'Repository is not clean' evendought git commitPitchman
C
332

It's a bug in Angular 8

you can work around it by using:

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

Claraclarabella answered 6/7, 2019 at 7:31 Comment(9)
this is not working .. giving error 'Repository is not clean. Update changes will be mixed with pre-existing changes. Using package manager: 'npm' Collecting installed dependencies... Found 0 dependencies. Package '@angular/cli' is not a dependency.'Outcrop
not working.., giving error 'Repository is no ...,' too.Clance
It's not a bug - it's an intentional feature which is applicable in the event that the CLI unintentionally updates a file that wasn't meant to be updated, potentially breaking your app.Baronetcy
@Baronetcy It's a bug when it issues this message incorrectly, as it is doing for me (v8.2)Dugout
This solution is valid for angular 12. ThanksDissuasive
ng update @angular/cli @angular/core --allow-dirty gives me the error: Package '@angular/cli' is not a dependency.Multiparous
Also need to add --forceCordle
Getting permission denied: ngSillsby
This is working for the angular 13 to 14 update as well.Amplexicaul
P
77

I have tried using mention command for upgrading from angular 8 to angular 9, but was still getting the error.

Then i have tried same command with --force flag and it worked for me.

ng update @angular/cli @angular/core --allow-dirty --force
Phelgen answered 17/2, 2020 at 9:41 Comment(0)
X
55

I've had the same issue. It's a common bug in Angular 8. Simply you can use dirty commands to bypass the repo check, such as (if u really need to bypass this, follow force commands)

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

but, I didn't do that. I followed following steps...

first of all double check whether you are commited all the changes before the update.then keep a copy of the project to the same location and commit the copy also to the Git. then run following command from the original project directory

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

afterwards u can delete the copy. This worked for me! thank you!

Xylene answered 14/4, 2020 at 17:20 Comment(0)
E
12

Worked for me

sudo npm update @angular/cli @angular/core --allow-dirty --legacy-peer-deps
Expediency answered 17/12, 2021 at 20:39 Comment(0)
G
6

The following worked for me to upgrade Angular 13 project to Angular 14 (October 2022):

In your project directory, open the command prompt with Admin rights. Then run the following command:

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

This should show an output similar to the below (may be different based on your existing Angular version):

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.

The following is my updated package.json file, after the upgrade:

{
  "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"
  }
}
Goodwife answered 8/10, 2022 at 14:46 Comment(1)
came across this, too, when upgrading from 13 to 14Atom
O
1

in my case, this was due to a node_modules folder not being excluded by the .gitignore. once added, this error no longer appeared

Outlet answered 16/7, 2020 at 17:24 Comment(0)
L
1

It is quite simple. Just commit it.

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

Angular just want you to "backup" minimally your work before updating. It is just a good practice.

Lizethlizette answered 24/2, 2023 at 9:44 Comment(0)
A
1

I asked every where and finally I got this recommend and it worked for me. I collect it from AIs and guide sites: The error message "Repository is not clean. Please commit or stash any changes before updating" indicates that there are uncommitted changes in your Git repository that need to be either committed or stashed before you can update Angular.

To solve this problem, you can follow these steps:

Open your terminal and navigate to your Angular project directory.

Run this command in terminal:

git status

to see the status of your Git repository.

If there are any uncommitted changes, you can either commit them by running the command :

git commit -m "commit message"

or stash them by running the command

git stash

Once you have committed or stashed your changes, run the command :

ng update @angular/core @angular/cli

again to update Angular.

After the update is complete, you can apply your changes back to the updated code by running the command :

git stash apply

if you stashed your changes, or by manually merging your changes if you committed them.

AND

Note: It is always a good practice to commit your changes before updating any dependencies in your project. This ensures that you have a backup of your code in case anything goes wrong during the update process.

Aylmar answered 9/5, 2023 at 6:43 Comment(0)
S
0

First, Check if there are any changes in your code that haven't pushed to git if yes push them, then close the old instance(cmd) and open a new instance of cmd then run the command. This worked for me, Thanks

Shirline answered 30/6, 2020 at 9:5 Comment(0)
T
0

It might appear in many cases. Just commit or stash any changes and run the command again.

Tyndareus answered 3/12, 2021 at 18:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.