0
0
Firebasecloud~5 mins

Rollback deployments in Firebase - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes after updating your app, you find a problem and want to go back to the previous working version. Rollback deployments lets you quickly restore your app to an earlier state to fix issues without downtime.
When a new app update causes errors or crashes for users.
When you accidentally deploy incomplete or broken code.
When you want to quickly undo a change that caused performance problems.
When you need to restore a stable version after testing a risky feature.
When you want to minimize downtime by reverting to a known good deployment.
Commands
This command lists all the deployed versions of your Firebase Hosting site so you can see which version to rollback to.
Terminal
firebase hosting:versions:list
Expected OutputExpected
Version ID Status Create Time v1 ACTIVE 2024-06-01T12:00:00Z v2 ACTIVE 2024-06-02T15:30:00Z v3 ACTIVE 2024-06-03T09:45:00Z
This command clones the version with ID 'v2' to prepare it for deployment again, effectively rolling back to that version.
Terminal
firebase hosting:versions:clone v2 --site=my-app
Expected OutputExpected
Cloning version v2 for site my-app... Version cloned successfully.
--site - Specifies the Firebase Hosting site to apply the rollback.
This command deploys the cloned version to Firebase Hosting, making the rollback live to users.
Terminal
firebase deploy --only hosting
Expected OutputExpected
=== Deploying to 'my-app'... i hosting: preparing hosting files... ✔ hosting: files prepared successfully i hosting: deploying... ✔ hosting: deployed successfully Project Console: https://console.firebase.google.com/project/my-app/overview ✔ Deploy complete!
--only hosting - Deploys only the hosting part without affecting other Firebase services.
This command opens the live channel URL so you can verify the rollback is visible to users.
Terminal
firebase hosting:channel:open live
Expected OutputExpected
Hosting URL: https://my-app.web.app You can now view your site live.
Key Concept

If you remember nothing else from this pattern, remember: rollback means redeploying a previous stable version to fix problems quickly.

Common Mistakes
Trying to rollback by redeploying old files manually without cloning the version.
This can cause mismatches and does not use Firebase's version control, risking inconsistent states.
Use 'firebase hosting:versions:clone' to clone the exact previous version before deploying.
Not specifying the correct site with --site flag when cloning versions.
The command will fail or clone the wrong site version, causing confusion or errors.
Always include --site=my-app (your site name) to target the right Firebase Hosting site.
Skipping the deploy step after cloning the version.
Cloning alone does not make the rollback live; you must deploy the cloned version.
Run 'firebase deploy --only hosting' after cloning to activate the rollback.
Summary
List all deployed versions with 'firebase hosting:versions:list' to find the rollback target.
Clone the desired previous version using 'firebase hosting:versions:clone' with the correct site.
Deploy the cloned version with 'firebase deploy --only hosting' to make rollback live.
Verify the rollback by opening the live hosting URL.