How to rollback last vendor publish in laravel

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

How to Rollback a vendor:publish in Laravel: Restoring Your Custom Assets

Dealing with accidental changes, especially when dealing with published files, can be incredibly frustrating. You execute a command intending to customize a template, but the result breaks your application flow. For developers working with frameworks like Laravel, understanding how to safely revert state is just as important as writing new features.

This post will guide you through the correct, professional methods for rolling back changes made via php artisan vendor:publish, focusing on safe practices and Git integration.


Understanding the Risk of vendor:publish

The command php artisan vendor:publish is a powerful tool used to copy files from the core Laravel vendor directory into your application's public or configuration directories. This is excellent for customizing default assets (like views, configuration files, or service providers).

However, when you publish these files, they become part of your project structure. If you make changes and then realize those changes were erroneous, simply deleting the published files might not be enough; you need a robust rollback strategy.

In your specific scenario—customizing email templates—you modified configuration assets that Laravel expects to remain consistent with its core setup. The goal is to restore the state before the publication occurred.

The Safest Rollback Method: Leveraging Git History

The absolute safest and most professional way to roll back any significant change in a Laravel project is by using version control, primarily Git. If you are following best practices (which we strongly encourage, as outlined on laravelcompany.com), every state of your code should be tracked.

If you committed your changes before running the vendor:publish command, reverting is trivial:

  1. Identify the Commit: Use git log to find the commit hash immediately preceding the erroneous publish command.
  2. Revert or Reset: You have two main options:
    • git revert <commit_hash>: This creates a new commit that undoes the changes introduced by that specific commit. This is safer if the published files have already been deployed or shared.
    • git reset --hard <commit_hash>: Use this only if you are working locally and are certain you want to completely discard all subsequent local changes and reset your branch history to a previous state. Use with caution!

If your publish command was the only change, reverting to the last committed state before that action will restore your desired configuration templates instantly.

Alternative: Manual Restoration (For Specific Files)

If you cannot rely on Git history for this specific rollback, you must manually restore the files. This method is less ideal for large-scale changes but can be useful for pinpoint fixes.

Since you were customizing email templates, these files are usually located within the resources/views or application configuration directories where Laravel looks for template assets.

  1. Locate Originals: Find a backup copy of your original, default template files (if you have them).
  2. Restore Manually: Overwrite the modified files with the correct defaults. For example, if you customized an email view, replace the modified file content with the original default structure.

Example Scenario (Conceptual): If you were customizing a view that Laravel automatically publishes, simply replacing that published file with the core version effectively rolls back the change.

# WARNING: This is conceptual; actual paths depend on where your publish command placed files.
# You would manually replace the modified template file with the default one.
cp /path/to/default/view.html ./path/to/published/view.html

Conclusion: Best Practices for Future Publishing

Accidents happen, but robust development requires proactive safety nets. Always treat published files as mutable assets that need version control protection. Before running any command that modifies application structure via vendor:publish, ensure you have a clean, committed snapshot of your current working state in Git.

By adopting a disciplined workflow—where publishing is preceded by a commit and protected by Git—you eliminate the risk of permanent data loss and ensure that your Laravel project remains stable and reproducible. Always prioritize version control when managing configuration and asset files on laravelcompany.com.