VCS Reset vs. Re‑run ng update After a Half‑Migrated Angular Upgrade
0 reputation · 07 Jun 2021, 15:49 UTC
0 reputation · 07 Jun 2021, 15:49 UTC
Recover an Angular workspace that was left in a half‑migrated state after a failed ng update run.
The migration process rewrites source files and updates package.json and the lockfile incrementally. If the process stops midway, earlier migrations may have already altered code, while later ones remain pending. Re‑running ng update on this polluted tree risks double‑applying or skipping transformations, and peer‑dependency conflicts may persist.
Should the upgrade be rolled back to a clean commit in version control and then re‑executed, or should the same upgrade be retried with --force or --allow-dirty after addressing the root cause?
git reset --hard to the last good commit and reinstalling dependencies the safest way to guarantee a clean baseline before re‑running ng update?ng update with --force after fixing peer‑dependency conflicts reliably apply the remaining migrations without double‑applying earlier changes?35275 reputation · 07 Jun 2021, 20:36 UTC
Roll back to the last good commit and re-run ng update from a clean tree. A forced retry with --force or --allow-dirty cannot reliably resume a half-finished migration, because Angular migrations are not idempotent and the CLI does not track which transformations already ran.
Migration schematics are written and tested against the pre-upgrade source tree. They assume, for example, that a particular import still exists or that a config key has its old shape. When ng update stops midway, earlier migrations have already rewritten files while later ones are pending. Re-running on that polluted tree gives you three bad outcomes:
Neither flag fixes this. --force only overrides npm peer-dependency conflicts during package installation. --allow-dirty only suppresses the clean-working-tree check. Both let the update proceed; neither makes migrations re-runnable or repairs the tree.
git status and git stash or commit work that exists only in the working tree. Remember git reset --hard discards tracked modifications, and untracked files survive unless you also run git clean — check before doing either.git reset --hard <last-good-commit>. This restores package.json and the lockfile along with the source.node_modules and run npm ci (or your package manager's frozen-lockfile install) so the baseline dependency set exactly matches what the migrations expect.--force, which can leave an inconsistent dependency set that breaks later migrations or the build.ng update and let it complete uninterrupted.ng update exits cleanly and git diff shows only the expected migration changes — no duplicated blocks or half-edited files.ng build and ng test on the re-migrated tree.package.json and the lockfile against the dependency set expected for your target Angular release.Exact flag behavior and migration idempotency vary by Angular version, and third-party package schematics can behave differently from official @angular/core migrations. The one diagnostic detail that could change this advice: if the failure happened before any source files were modified (e.g., it died during dependency resolution), a plain retry after fixing the peer conflict is safe — check git status to see whether the tree was actually touched.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.